{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 本周知识-柱状图"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 基本柱状图的绘制"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "    <div class=\"bk-root\">\n",
       "        <a href=\"https://bokeh.org\" target=\"_blank\" class=\"bk-logo bk-logo-small bk-logo-notebook\"></a>\n",
       "        <span id=\"1001\">Loading BokehJS ...</span>\n",
       "    </div>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "\n",
       "(function(root) {\n",
       "  function now() {\n",
       "    return new Date();\n",
       "  }\n",
       "\n",
       "  var force = true;\n",
       "\n",
       "  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n",
       "    root._bokeh_onload_callbacks = [];\n",
       "    root._bokeh_is_loading = undefined;\n",
       "  }\n",
       "\n",
       "  var JS_MIME_TYPE = 'application/javascript';\n",
       "  var HTML_MIME_TYPE = 'text/html';\n",
       "  var EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n",
       "  var CLASS_NAME = 'output_bokeh rendered_html';\n",
       "\n",
       "  /**\n",
       "   * Render data to the DOM node\n",
       "   */\n",
       "  function render(props, node) {\n",
       "    var script = document.createElement(\"script\");\n",
       "    node.appendChild(script);\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when an output is cleared or removed\n",
       "   */\n",
       "  function handleClearOutput(event, handle) {\n",
       "    var cell = handle.cell;\n",
       "\n",
       "    var id = cell.output_area._bokeh_element_id;\n",
       "    var server_id = cell.output_area._bokeh_server_id;\n",
       "    // Clean up Bokeh references\n",
       "    if (id != null && id in Bokeh.index) {\n",
       "      Bokeh.index[id].model.document.clear();\n",
       "      delete Bokeh.index[id];\n",
       "    }\n",
       "\n",
       "    if (server_id !== undefined) {\n",
       "      // Clean up Bokeh references\n",
       "      var cmd = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n",
       "      cell.notebook.kernel.execute(cmd, {\n",
       "        iopub: {\n",
       "          output: function(msg) {\n",
       "            var id = msg.content.text.trim();\n",
       "            if (id in Bokeh.index) {\n",
       "              Bokeh.index[id].model.document.clear();\n",
       "              delete Bokeh.index[id];\n",
       "            }\n",
       "          }\n",
       "        }\n",
       "      });\n",
       "      // Destroy server and session\n",
       "      var cmd = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n",
       "      cell.notebook.kernel.execute(cmd);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  /**\n",
       "   * Handle when a new output is added\n",
       "   */\n",
       "  function handleAddOutput(event, handle) {\n",
       "    var output_area = handle.output_area;\n",
       "    var output = handle.output;\n",
       "\n",
       "    // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n",
       "    if ((output.output_type != \"display_data\") || (!output.data.hasOwnProperty(EXEC_MIME_TYPE))) {\n",
       "      return\n",
       "    }\n",
       "\n",
       "    var toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n",
       "\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n",
       "      toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n",
       "      // store reference to embed id on output_area\n",
       "      output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n",
       "    }\n",
       "    if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n",
       "      var bk_div = document.createElement(\"div\");\n",
       "      bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n",
       "      var script_attrs = bk_div.children[0].attributes;\n",
       "      for (var i = 0; i < script_attrs.length; i++) {\n",
       "        toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n",
       "        toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n",
       "      }\n",
       "      // store reference to server id on output_area\n",
       "      output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n",
       "    }\n",
       "  }\n",
       "\n",
       "  function register_renderer(events, OutputArea) {\n",
       "\n",
       "    function append_mime(data, metadata, element) {\n",
       "      // create a DOM node to render to\n",
       "      var toinsert = this.create_output_subarea(\n",
       "        metadata,\n",
       "        CLASS_NAME,\n",
       "        EXEC_MIME_TYPE\n",
       "      );\n",
       "      this.keyboard_manager.register_events(toinsert);\n",
       "      // Render to node\n",
       "      var props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n",
       "      render(props, toinsert[toinsert.length - 1]);\n",
       "      element.append(toinsert);\n",
       "      return toinsert\n",
       "    }\n",
       "\n",
       "    /* Handle when an output is cleared or removed */\n",
       "    events.on('clear_output.CodeCell', handleClearOutput);\n",
       "    events.on('delete.Cell', handleClearOutput);\n",
       "\n",
       "    /* Handle when a new output is added */\n",
       "    events.on('output_added.OutputArea', handleAddOutput);\n",
       "\n",
       "    /**\n",
       "     * Register the mime type and append_mime function with output_area\n",
       "     */\n",
       "    OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n",
       "      /* Is output safe? */\n",
       "      safe: true,\n",
       "      /* Index of renderer in `output_area.display_order` */\n",
       "      index: 0\n",
       "    });\n",
       "  }\n",
       "\n",
       "  // register the mime type if in Jupyter Notebook environment and previously unregistered\n",
       "  if (root.Jupyter !== undefined) {\n",
       "    var events = require('base/js/events');\n",
       "    var OutputArea = require('notebook/js/outputarea').OutputArea;\n",
       "\n",
       "    if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n",
       "      register_renderer(events, OutputArea);\n",
       "    }\n",
       "  }\n",
       "\n",
       "  \n",
       "  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n",
       "    root._bokeh_timeout = Date.now() + 5000;\n",
       "    root._bokeh_failed_load = false;\n",
       "  }\n",
       "\n",
       "  var NB_LOAD_WARNING = {'data': {'text/html':\n",
       "     \"<div style='background-color: #fdd'>\\n\"+\n",
       "     \"<p>\\n\"+\n",
       "     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n",
       "     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n",
       "     \"</p>\\n\"+\n",
       "     \"<ul>\\n\"+\n",
       "     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n",
       "     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n",
       "     \"</ul>\\n\"+\n",
       "     \"<code>\\n\"+\n",
       "     \"from bokeh.resources import INLINE\\n\"+\n",
       "     \"output_notebook(resources=INLINE)\\n\"+\n",
       "     \"</code>\\n\"+\n",
       "     \"</div>\"}};\n",
       "\n",
       "  function display_loaded() {\n",
       "    var el = document.getElementById(\"1001\");\n",
       "    if (el != null) {\n",
       "      el.textContent = \"BokehJS is loading...\";\n",
       "    }\n",
       "    if (root.Bokeh !== undefined) {\n",
       "      if (el != null) {\n",
       "        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n",
       "      }\n",
       "    } else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(display_loaded, 100)\n",
       "    }\n",
       "  }\n",
       "\n",
       "\n",
       "  function run_callbacks() {\n",
       "    try {\n",
       "      root._bokeh_onload_callbacks.forEach(function(callback) {\n",
       "        if (callback != null)\n",
       "          callback();\n",
       "      });\n",
       "    } finally {\n",
       "      delete root._bokeh_onload_callbacks\n",
       "    }\n",
       "    console.debug(\"Bokeh: all callbacks have finished\");\n",
       "  }\n",
       "\n",
       "  function load_libs(css_urls, js_urls, callback) {\n",
       "    if (css_urls == null) css_urls = [];\n",
       "    if (js_urls == null) js_urls = [];\n",
       "\n",
       "    root._bokeh_onload_callbacks.push(callback);\n",
       "    if (root._bokeh_is_loading > 0) {\n",
       "      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n",
       "      return null;\n",
       "    }\n",
       "    if (js_urls == null || js_urls.length === 0) {\n",
       "      run_callbacks();\n",
       "      return null;\n",
       "    }\n",
       "    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n",
       "    root._bokeh_is_loading = css_urls.length + js_urls.length;\n",
       "\n",
       "    function on_load() {\n",
       "      root._bokeh_is_loading--;\n",
       "      if (root._bokeh_is_loading === 0) {\n",
       "        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n",
       "        run_callbacks()\n",
       "      }\n",
       "    }\n",
       "\n",
       "    function on_error() {\n",
       "      console.error(\"failed to load \" + url);\n",
       "    }\n",
       "\n",
       "    for (var i = 0; i < css_urls.length; i++) {\n",
       "      var url = css_urls[i];\n",
       "      const element = document.createElement(\"link\");\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error;\n",
       "      element.rel = \"stylesheet\";\n",
       "      element.type = \"text/css\";\n",
       "      element.href = url;\n",
       "      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n",
       "      document.body.appendChild(element);\n",
       "    }\n",
       "\n",
       "    const hashes = {\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\": \"kLr4fYcqcSpbuI95brIH3vnnYCquzzSxHPU6XGQCIkQRGJwhg0StNbj1eegrHs12\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\": \"xIGPmVtaOm+z0BqfSOMn4lOR6ciex448GIKG4eE61LsAvmGj48XcMQZtKcE/UXZe\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\": \"Dc9u1wF/0zApGIWoBbH77iWEHtdmkuYWG839Uzmv8y8yBLXebjO9ZnERsde5Ln/P\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\": \"cT9JaBz7GiRXdENrJLZNSC6eMNF3nh3fa5fTF51Svp+ukxPdwcU5kGXGPBgDCa2j\"};\n",
       "\n",
       "    for (var i = 0; i < js_urls.length; i++) {\n",
       "      var url = js_urls[i];\n",
       "      var element = document.createElement('script');\n",
       "      element.onload = on_load;\n",
       "      element.onerror = on_error;\n",
       "      element.async = false;\n",
       "      element.src = url;\n",
       "      if (url in hashes) {\n",
       "        element.crossOrigin = \"anonymous\";\n",
       "        element.integrity = \"sha384-\" + hashes[url];\n",
       "      }\n",
       "      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n",
       "      document.head.appendChild(element);\n",
       "    }\n",
       "  };\n",
       "\n",
       "  function inject_raw_css(css) {\n",
       "    const element = document.createElement(\"style\");\n",
       "    element.appendChild(document.createTextNode(css));\n",
       "    document.body.appendChild(element);\n",
       "  }\n",
       "\n",
       "  \n",
       "  var js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\"];\n",
       "  var css_urls = [];\n",
       "  \n",
       "\n",
       "  var inline_js = [\n",
       "    function(Bokeh) {\n",
       "      Bokeh.set_log_level(\"info\");\n",
       "    },\n",
       "    function(Bokeh) {\n",
       "    \n",
       "    \n",
       "    }\n",
       "  ];\n",
       "\n",
       "  function run_inline_js() {\n",
       "    \n",
       "    if (root.Bokeh !== undefined || force === true) {\n",
       "      \n",
       "    for (var i = 0; i < inline_js.length; i++) {\n",
       "      inline_js[i].call(root, root.Bokeh);\n",
       "    }\n",
       "    if (force === true) {\n",
       "        display_loaded();\n",
       "      }} else if (Date.now() < root._bokeh_timeout) {\n",
       "      setTimeout(run_inline_js, 100);\n",
       "    } else if (!root._bokeh_failed_load) {\n",
       "      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n",
       "      root._bokeh_failed_load = true;\n",
       "    } else if (force !== true) {\n",
       "      var cell = $(document.getElementById(\"1001\")).parents('.cell').data().cell;\n",
       "      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n",
       "    }\n",
       "\n",
       "  }\n",
       "\n",
       "  if (root._bokeh_is_loading === 0) {\n",
       "    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n",
       "    run_inline_js();\n",
       "  } else {\n",
       "    load_libs(css_urls, js_urls, function() {\n",
       "      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n",
       "      run_inline_js();\n",
       "    });\n",
       "  }\n",
       "}(window));"
      ],
      "application/vnd.bokehjs_load.v0+json": "\n(function(root) {\n  function now() {\n    return new Date();\n  }\n\n  var force = true;\n\n  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n    root._bokeh_onload_callbacks = [];\n    root._bokeh_is_loading = undefined;\n  }\n\n  \n\n  \n  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n    root._bokeh_timeout = Date.now() + 5000;\n    root._bokeh_failed_load = false;\n  }\n\n  var NB_LOAD_WARNING = {'data': {'text/html':\n     \"<div style='background-color: #fdd'>\\n\"+\n     \"<p>\\n\"+\n     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n     \"</p>\\n\"+\n     \"<ul>\\n\"+\n     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n     \"</ul>\\n\"+\n     \"<code>\\n\"+\n     \"from bokeh.resources import INLINE\\n\"+\n     \"output_notebook(resources=INLINE)\\n\"+\n     \"</code>\\n\"+\n     \"</div>\"}};\n\n  function display_loaded() {\n    var el = document.getElementById(\"1001\");\n    if (el != null) {\n      el.textContent = \"BokehJS is loading...\";\n    }\n    if (root.Bokeh !== undefined) {\n      if (el != null) {\n        el.textContent = \"BokehJS \" + root.Bokeh.version + \" successfully loaded.\";\n      }\n    } else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(display_loaded, 100)\n    }\n  }\n\n\n  function run_callbacks() {\n    try {\n      root._bokeh_onload_callbacks.forEach(function(callback) {\n        if (callback != null)\n          callback();\n      });\n    } finally {\n      delete root._bokeh_onload_callbacks\n    }\n    console.debug(\"Bokeh: all callbacks have finished\");\n  }\n\n  function load_libs(css_urls, js_urls, callback) {\n    if (css_urls == null) css_urls = [];\n    if (js_urls == null) js_urls = [];\n\n    root._bokeh_onload_callbacks.push(callback);\n    if (root._bokeh_is_loading > 0) {\n      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n      return null;\n    }\n    if (js_urls == null || js_urls.length === 0) {\n      run_callbacks();\n      return null;\n    }\n    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n    root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n    function on_load() {\n      root._bokeh_is_loading--;\n      if (root._bokeh_is_loading === 0) {\n        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n        run_callbacks()\n      }\n    }\n\n    function on_error() {\n      console.error(\"failed to load \" + url);\n    }\n\n    for (var i = 0; i < css_urls.length; i++) {\n      var url = css_urls[i];\n      const element = document.createElement(\"link\");\n      element.onload = on_load;\n      element.onerror = on_error;\n      element.rel = \"stylesheet\";\n      element.type = \"text/css\";\n      element.href = url;\n      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n      document.body.appendChild(element);\n    }\n\n    const hashes = {\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\": \"kLr4fYcqcSpbuI95brIH3vnnYCquzzSxHPU6XGQCIkQRGJwhg0StNbj1eegrHs12\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\": \"xIGPmVtaOm+z0BqfSOMn4lOR6ciex448GIKG4eE61LsAvmGj48XcMQZtKcE/UXZe\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\": \"Dc9u1wF/0zApGIWoBbH77iWEHtdmkuYWG839Uzmv8y8yBLXebjO9ZnERsde5Ln/P\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\": \"cT9JaBz7GiRXdENrJLZNSC6eMNF3nh3fa5fTF51Svp+ukxPdwcU5kGXGPBgDCa2j\"};\n\n    for (var i = 0; i < js_urls.length; i++) {\n      var url = js_urls[i];\n      var element = document.createElement('script');\n      element.onload = on_load;\n      element.onerror = on_error;\n      element.async = false;\n      element.src = url;\n      if (url in hashes) {\n        element.crossOrigin = \"anonymous\";\n        element.integrity = \"sha384-\" + hashes[url];\n      }\n      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n      document.head.appendChild(element);\n    }\n  };\n\n  function inject_raw_css(css) {\n    const element = document.createElement(\"style\");\n    element.appendChild(document.createTextNode(css));\n    document.body.appendChild(element);\n  }\n\n  \n  var js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-2.1.1.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-2.1.1.min.js\"];\n  var css_urls = [];\n  \n\n  var inline_js = [\n    function(Bokeh) {\n      Bokeh.set_log_level(\"info\");\n    },\n    function(Bokeh) {\n    \n    \n    }\n  ];\n\n  function run_inline_js() {\n    \n    if (root.Bokeh !== undefined || force === true) {\n      \n    for (var i = 0; i < inline_js.length; i++) {\n      inline_js[i].call(root, root.Bokeh);\n    }\n    if (force === true) {\n        display_loaded();\n      }} else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(run_inline_js, 100);\n    } else if (!root._bokeh_failed_load) {\n      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n      root._bokeh_failed_load = true;\n    } else if (force !== true) {\n      var cell = $(document.getElementById(\"1001\")).parents('.cell').data().cell;\n      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n    }\n\n  }\n\n  if (root._bokeh_is_loading === 0) {\n    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n    run_inline_js();\n  } else {\n    load_libs(css_urls, js_urls, function() {\n      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n      run_inline_js();\n    });\n  }\n}(window));"
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.plotting import output_notebook,figure,show\n",
    "output_notebook()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 垂直柱状图\n",
    "* 绘制方法\n",
    "> vbar()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"5df134b0-3d8f-40b2-b311-7e5743ffc4a9\" data-root-id=\"1002\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"dc009e4b-87b7-4106-99da-0662c3d17b69\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1011\"}],\"center\":[{\"id\":\"1014\"},{\"id\":\"1018\"}],\"left\":[{\"id\":\"1015\"}],\"plot_height\":400,\"plot_width\":400,\"renderers\":[{\"id\":\"1036\"}],\"title\":{\"id\":\"1038\"},\"toolbar\":{\"id\":\"1026\"},\"x_range\":{\"id\":\"1003\"},\"x_scale\":{\"id\":\"1007\"},\"y_range\":{\"id\":\"1005\"},\"y_scale\":{\"id\":\"1009\"}},\"id\":\"1002\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"formatter\":{\"id\":\"1042\"},\"ticker\":{\"id\":\"1016\"}},\"id\":\"1015\",\"type\":\"LinearAxis\"},{\"attributes\":{\"data_source\":{\"id\":\"1033\"},\"glyph\":{\"id\":\"1034\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1035\"},\"selection_glyph\":null,\"view\":{\"id\":\"1037\"}},\"id\":\"1036\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1022\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1016\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1040\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"source\":{\"id\":\"1033\"}},\"id\":\"1037\",\"type\":\"CDSView\"},{\"attributes\":{\"axis\":{\"id\":\"1015\"},\"dimension\":1,\"ticker\":null},\"id\":\"1018\",\"type\":\"Grid\"},{\"attributes\":{\"overlay\":{\"id\":\"1025\"}},\"id\":\"1021\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"text\":\"\"},\"id\":\"1038\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1045\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"pink\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"pink\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.5},\"x\":{\"field\":\"x\"}},\"id\":\"1035\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1020\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1042\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1012\",\"type\":\"BasicTicker\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1019\"},{\"id\":\"1020\"},{\"id\":\"1021\"},{\"id\":\"1022\"},{\"id\":\"1023\"},{\"id\":\"1024\"}]},\"id\":\"1026\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1023\",\"type\":\"ResetTool\"},{\"attributes\":{\"fill_color\":{\"value\":\"pink\"},\"line_color\":{\"value\":\"pink\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.5},\"x\":{\"field\":\"x\"}},\"id\":\"1034\",\"type\":\"VBar\"},{\"attributes\":{\"data\":{\"top\":[1.2,2.6,3.5],\"x\":[1,2,3]},\"selected\":{\"id\":\"1046\"},\"selection_policy\":{\"id\":\"1045\"}},\"id\":\"1033\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1046\",\"type\":\"Selection\"},{\"attributes\":{\"formatter\":{\"id\":\"1040\"},\"ticker\":{\"id\":\"1012\"}},\"id\":\"1011\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1003\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1024\",\"type\":\"HelpTool\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1025\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1007\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1019\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1005\",\"type\":\"DataRange1d\"},{\"attributes\":{\"axis\":{\"id\":\"1011\"},\"ticker\":null},\"id\":\"1014\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1009\",\"type\":\"LinearScale\"}],\"root_ids\":[\"1002\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"dc009e4b-87b7-4106-99da-0662c3d17b69\",\"root_ids\":[\"1002\"],\"roots\":{\"1002\":\"5df134b0-3d8f-40b2-b311-7e5743ffc4a9\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1002"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画布绘制\n",
    "p = figure(plot_width=400,plot_height=400)\n",
    "p.vbar(\n",
    "    x=[1,2,3],\n",
    "    width=0.5,\n",
    "    bottom=0,\n",
    "    color=\"pink\",\n",
    "    top=[1.2,2.6,3.5]\n",
    ")\n",
    "\n",
    "#显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on method vbar in module bokeh.plotting.figure:\n",
      "\n",
      "vbar(x, width, top, bottom=0, *, fill_alpha=1.0, fill_color='gray', hatch_alpha=1.0, hatch_color='black', hatch_extra={}, hatch_pattern=None, hatch_scale=12.0, hatch_weight=1.0, line_alpha=1.0, line_cap='butt', line_color='black', line_dash=[], line_dash_offset=0, line_join='bevel', line_width=1, name=None, tags=[], **kwargs) method of bokeh.plotting.figure.Figure instance\n",
      "    Configure and add :class:`~bokeh.models.glyphs.VBar` glyphs to this Figure.\n",
      "    \n",
      "    Args:\n",
      "        x (:class:`~bokeh.core.properties.NumberSpec` ):\n",
      "            The x-coordinates of the centers of the vertical bars.\n",
      "    \n",
      "        width (:class:`~bokeh.core.properties.NumberSpec` ):\n",
      "            The widths of the vertical bars.\n",
      "    \n",
      "        top (:class:`~bokeh.core.properties.NumberSpec` ):\n",
      "            The y-coordinates of the top edges.\n",
      "    \n",
      "        bottom (:class:`~bokeh.core.properties.NumberSpec` ):\n",
      "            The y-coordinates of the bottom edges.\n",
      "    \n",
      "            (default: 0)\n",
      "    \n",
      "    \n",
      "    Keyword args:\n",
      "        fill_alpha (:class:`~bokeh.core.properties.NumberSpec` , optional):\n",
      "            The fill alpha values for the vertical bars.\n",
      "    \n",
      "            (default: 1.0)\n",
      "    \n",
      "        fill_color (:class:`~bokeh.core.properties.ColorSpec` , optional):\n",
      "            The fill color values for the vertical bars.\n",
      "    \n",
      "            (default: gray)\n",
      "    \n",
      "        hatch_alpha (:class:`~bokeh.core.properties.NumberSpec` , optional):\n",
      "            The hatch alpha values for the vertical bars.\n",
      "    \n",
      "            (default: 1.0)\n",
      "    \n",
      "        hatch_color (:class:`~bokeh.core.properties.ColorSpec` , optional):\n",
      "            The hatch color values for the vertical bars.\n",
      "    \n",
      "            (default: black)\n",
      "    \n",
      "        hatch_extra (:class:`~bokeh.core.properties.Dict` ( :class:`~bokeh.core.properties.String` , :class:`~bokeh.core.properties.Instance` ( :class:`~bokeh.models.textures.Texture`  ) )):\n",
      "            The hatch extra values for the vertical bars.\n",
      "    \n",
      "            (default: {})\n",
      "    \n",
      "        hatch_pattern (:class:`~bokeh.core.properties.HatchPatternSpec` ):\n",
      "            The hatch pattern values for the vertical bars.\n",
      "    \n",
      "        hatch_scale (:class:`~bokeh.core.properties.NumberSpec` , optional):\n",
      "            The hatch scale values for the vertical bars.\n",
      "    \n",
      "            (default: 12.0)\n",
      "    \n",
      "        hatch_weight (:class:`~bokeh.core.properties.NumberSpec` , optional):\n",
      "            The hatch weight values for the vertical bars.\n",
      "    \n",
      "            (default: 1.0)\n",
      "    \n",
      "        line_alpha (:class:`~bokeh.core.properties.NumberSpec` , optional):\n",
      "            The line alpha values for the vertical bars.\n",
      "    \n",
      "            (default: 1.0)\n",
      "    \n",
      "        line_cap (:class:`~bokeh.core.properties.Enum` ( :class:`~bokeh.core.enums.LineCap`  ), optional):\n",
      "            The line cap values for the vertical bars.\n",
      "    \n",
      "            (default: butt)\n",
      "    \n",
      "        line_color (:class:`~bokeh.core.properties.ColorSpec` , optional):\n",
      "            The line color values for the vertical bars.\n",
      "    \n",
      "            (default: black)\n",
      "    \n",
      "        line_dash (:class:`~bokeh.core.properties.DashPattern` ):\n",
      "            The line dash values for the vertical bars.\n",
      "    \n",
      "            (default: [])\n",
      "    \n",
      "        line_dash_offset (:class:`~bokeh.core.properties.Int` ):\n",
      "            The line dash offset values for the vertical bars.\n",
      "    \n",
      "            (default: 0)\n",
      "    \n",
      "        line_join (:class:`~bokeh.core.properties.Enum` ( :class:`~bokeh.core.enums.LineJoin`  ), optional):\n",
      "            The line join values for the vertical bars.\n",
      "    \n",
      "            (default: bevel)\n",
      "    \n",
      "        line_width (:class:`~bokeh.core.properties.NumberSpec` , optional):\n",
      "            The line width values for the vertical bars.\n",
      "    \n",
      "            (default: 1)\n",
      "    \n",
      "        name (:class:`~bokeh.core.properties.String` ):\n",
      "            An arbitrary, user-supplied name for this model.\n",
      "        \n",
      "            This name can be useful when querying the document to retrieve specific\n",
      "            Bokeh models.\n",
      "        \n",
      "            .. code:: python\n",
      "        \n",
      "                >>> plot.circle([1,2,3], [4,5,6], name=\"temp\")\n",
      "                >>> plot.select(name=\"temp\")\n",
      "                [GlyphRenderer(id='399d53f5-73e9-44d9-9527-544b761c7705', ...)]\n",
      "        \n",
      "            .. note::\n",
      "                No uniqueness guarantees or other conditions are enforced on any names\n",
      "                that are provided, nor is the name used directly by Bokeh for any\n",
      "                reason.\n",
      "    \n",
      "        tags (:class:`~bokeh.core.properties.List` ( :class:`~bokeh.core.properties.Any`  )):\n",
      "            An optional list of arbitrary, user-supplied values to attach to this\n",
      "            model.\n",
      "        \n",
      "            This data can be useful when querying the document to retrieve specific\n",
      "            Bokeh models:\n",
      "        \n",
      "            .. code:: python\n",
      "        \n",
      "                >>> r = plot.circle([1,2,3], [4,5,6])\n",
      "                >>> r.tags = [\"foo\", 10]\n",
      "                >>> plot.select(tags=['foo', 10])\n",
      "                [GlyphRenderer(id='1de4c3df-a83d-480a-899b-fb263d3d5dd9', ...)]\n",
      "        \n",
      "            Or simply a convenient way to attach any necessary metadata to a model\n",
      "            that can be accessed by ``CustomJS`` callbacks, etc.\n",
      "        \n",
      "            .. note::\n",
      "                No uniqueness guarantees or other conditions are enforced on any tags\n",
      "                that are provided, nor are the tags used directly by Bokeh for any\n",
      "                reason.\n",
      "    \n",
      "            (default: [])\n",
      "    \n",
      "    \n",
      "    \n",
      "    Other Parameters:\n",
      "        alpha (float, optional) :\n",
      "            An alias to set all alpha keyword arguments at once. (default: None)\n",
      "    \n",
      "            Alpha values must be between 0 (fully transparent) and 1 (fully opaque).\n",
      "    \n",
      "            Any explicitly set values for ``line_alpha``, etc. will override this\n",
      "            setting.\n",
      "    \n",
      "        color (Color, optional) :\n",
      "            An alias to set all color keyword arguments at once. (default: None)\n",
      "    \n",
      "            Acceptable values for colors are described in the `Specifying Colors`_\n",
      "            section of the User's Guide.\n",
      "    \n",
      "            Any explicitly set values for ``line_color``, etc. will override this\n",
      "            setting.\n",
      "    \n",
      "            .. _Specifying Colors: https://docs.bokeh.org/en/latest/docs/user_guide/styling.html#specifying-colors\n",
      "    \n",
      "        legend_field (str, optional) :\n",
      "            Specify that the glyph should produce multiple legend entried by\n",
      "            `Grouping in the Browser`_. The value of this parameter is the name of a\n",
      "            column in the data source that should be used or the grouping.\n",
      "    \n",
      "            The grouping is performed *in JavaScript*, at the time time the Bokeh\n",
      "            content is rendered in the browser. If the data is subsequently updated,\n",
      "            the legend will automatically re-group.\n",
      "    \n",
      "            .. note::\n",
      "                Only one of ``legend_field``, ``legend_group``, or ``legend_label``\n",
      "                should be supplied\n",
      "    \n",
      "            .. _Grouping in the Browser: https://docs.bokeh.org/en/latest/docs/user_guide/annotations.html#automatic-grouping-browser\n",
      "    \n",
      "        legend_group (str, optional) :\n",
      "            Specify that the glyph should produce multiple legend entried by\n",
      "            `Grouping in Python`_. The value of this parameter is the name of a\n",
      "            column in the data source that should be used or the grouping.\n",
      "    \n",
      "            The grouping is performed in Python, before the Bokeh output is sent to\n",
      "            a browser. If the date is subsequently updated, the legend will *not*\n",
      "            automatically re-group.\n",
      "    \n",
      "            .. note::\n",
      "                Only one of ``legend_field``, ``legend_group``, or ``legend_label``\n",
      "                should be supplied\n",
      "    \n",
      "            .. _Grouping in Python: https://docs.bokeh.org/en/latest/docs/user_guide/annotations.html#automatic-grouping-python\n",
      "    \n",
      "        legend_label (str, optional) :\n",
      "            Specify that the glyph should produce a single `Basic Legend Label`_ in\n",
      "            the legend. The legend entry is labeled with exactly the text supplied\n",
      "            here.\n",
      "    \n",
      "            .. note::\n",
      "                Only one of ``legend_field``, ``legend_group``, or ``legend_label``\n",
      "                should be supplied\n",
      "    \n",
      "            .. _Basic Legend Label: https://docs.bokeh.org/en/latest/docs/user_guide/annotations.html#basic-legend-label\n",
      "    \n",
      "        muted (bool, optionall) :\n",
      "            Whether the glyph should be rendered as muted (default: False)\n",
      "    \n",
      "            For this to be useful, an ``muted_glyph`` must be configured on the\n",
      "            returned ``GlyphRender``. This can be done by explicitly creating a\n",
      "            ``Glyph`` to use, or more simply by passing e.g. ``muted_color``, etc.\n",
      "            to this glyph function.\n",
      "    \n",
      "        name (str, optional) :\n",
      "            An optional user-supplied name to attach to the renderer (default: None)\n",
      "    \n",
      "            Bokeh does not use this value in any way, but it may be useful for\n",
      "            searching a Bokeh document to find a specific model.\n",
      "    \n",
      "        source (ColumnDataSource, optional) :\n",
      "            A user-supplied data source. (defatult: None)\n",
      "    \n",
      "            If not supplied, Bokeh will automatically construct an internal\n",
      "            ``ColumnDataSource`` with default column names from the coordinates and\n",
      "            other arguments that were passed-in as literal list or array values.\n",
      "    \n",
      "            If supplied, Bokeh will use the supplied data source to drive the glyph.\n",
      "            In this case, literal list or arrays may not be used for coordinates or\n",
      "            other arguments. Only singular fixed valued (e.g. ``x=10``) or column\n",
      "            names in the data souce (e.g. ``x=\"time\"``) are permitted.\n",
      "    \n",
      "        view (CDSView, optional) :\n",
      "            A view for filtering the data source. (default: None)\n",
      "    \n",
      "        visible (bool, optional) :\n",
      "            Whether the glyph should be rendered. (default: True)\n",
      "    \n",
      "        x_range_name (str, optional) :\n",
      "            The name of an extra range to use for mapping x-coordinates.\n",
      "            (default: None)\n",
      "    \n",
      "            If not supplied, then the default ``y_range`` of the plot will be used\n",
      "            for coordinate mapping.\n",
      "    \n",
      "        y_range_name (str, optional) :\n",
      "            The name of an extra range to use for mapping y-coordinates.\n",
      "            (default: None)\n",
      "    \n",
      "            If not supplied, then the default ``y_range`` of the plot will be used\n",
      "            for coordinate mapping.\n",
      "    \n",
      "        level (RenderLevel, optional) :\n",
      "            Specify the render level order for this glyph.\n",
      "    \n",
      "    \n",
      "    \n",
      "    It is also possible to set the color and alpha parameters of extra glyphs for\n",
      "    selection, nonselection, hover, or muted. To do so, add the relevane prefix to\n",
      "    any visual parameter. For example, pass ``nonselection_alpha`` to set the line\n",
      "    and fill alpha for nonselect, or ``hover_fill_alpha`` to set the fill alpha for\n",
      "    hover. See the `Glyphs`_ section od the User's Guide for full details.\n",
      "    \n",
      "    .. _Glyphs: https://docs.bokeh.org/en/latest/docs/user_guide/styling.html#glyphs\n",
      "    \n",
      "    Returns:\n",
      "        :class:`~bokeh.models.renderers.GlyphRenderer`\n",
      "    \n",
      "    \n",
      "    Examples:\n",
      "    \n",
      "        .. bokeh-plot::\n",
      "            :source-position: above\n",
      "    \n",
      "            from bokeh.plotting import figure, output_file, show\n",
      "    \n",
      "            plot = figure(plot_width=300, plot_height=300)\n",
      "            plot.vbar(x=[1, 2, 3], width=0.5, bottom=0, top=[1,2,3], color=\"#CAB2D6\")\n",
      "    \n",
      "            show(plot)\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(p.vbar)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 水平的柱状图\n",
    "* 绘制方法\n",
    "> hbar()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "#查看使用方法\n",
    "??p.hbar"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"9180fc6d-d040-4e48-938c-d3b5c4424102\" data-root-id=\"1101\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"0f9ccc63-4d75-43cf-9c97-238d5f541f58\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1112\"}],\"center\":[{\"id\":\"1115\"},{\"id\":\"1119\"}],\"left\":[{\"id\":\"1116\"}],\"plot_height\":400,\"plot_width\":400,\"renderers\":[{\"id\":\"1137\"}],\"title\":{\"id\":\"1102\"},\"toolbar\":{\"id\":\"1127\"},\"x_range\":{\"id\":\"1104\"},\"x_scale\":{\"id\":\"1108\"},\"y_range\":{\"id\":\"1106\"},\"y_scale\":{\"id\":\"1110\"}},\"id\":\"1101\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1126\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1120\",\"type\":\"PanTool\"},{\"attributes\":{\"data\":{\"right\":[1.5,2.5,3.7],\"y\":[1,2,3]},\"selected\":{\"id\":\"1155\"},\"selection_policy\":{\"id\":\"1154\"}},\"id\":\"1134\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1120\"},{\"id\":\"1121\"},{\"id\":\"1122\"},{\"id\":\"1123\"},{\"id\":\"1124\"},{\"id\":\"1125\"}]},\"id\":\"1127\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1155\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1154\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1108\",\"type\":\"LinearScale\"},{\"attributes\":{\"data_source\":{\"id\":\"1134\"},\"glyph\":{\"id\":\"1135\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1136\"},\"selection_glyph\":null,\"view\":{\"id\":\"1138\"}},\"id\":\"1137\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1110\",\"type\":\"LinearScale\"},{\"attributes\":{\"source\":{\"id\":\"1134\"}},\"id\":\"1138\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1121\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1149\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1106\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1151\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1123\",\"type\":\"SaveTool\"},{\"attributes\":{\"text\":\"\\u6c34\\u5e73\\u67f1\\u72b6\\u56feDemo\"},\"id\":\"1102\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1125\",\"type\":\"HelpTool\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"yellow\"},\"height\":{\"value\":0.5},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"yellow\"},\"right\":{\"field\":\"right\"},\"y\":{\"field\":\"y\"}},\"id\":\"1136\",\"type\":\"HBar\"},{\"attributes\":{\"formatter\":{\"id\":\"1151\"},\"ticker\":{\"id\":\"1117\"}},\"id\":\"1116\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1117\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1124\",\"type\":\"ResetTool\"},{\"attributes\":{\"axis\":{\"id\":\"1116\"},\"dimension\":1,\"ticker\":null},\"id\":\"1119\",\"type\":\"Grid\"},{\"attributes\":{\"formatter\":{\"id\":\"1149\"},\"ticker\":{\"id\":\"1113\"}},\"id\":\"1112\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1104\",\"type\":\"DataRange1d\"},{\"attributes\":{\"axis\":{\"id\":\"1112\"},\"ticker\":null},\"id\":\"1115\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1113\",\"type\":\"BasicTicker\"},{\"attributes\":{\"fill_color\":{\"value\":\"yellow\"},\"height\":{\"value\":0.5},\"line_color\":{\"value\":\"yellow\"},\"right\":{\"field\":\"right\"},\"y\":{\"field\":\"y\"}},\"id\":\"1135\",\"type\":\"HBar\"},{\"attributes\":{\"overlay\":{\"id\":\"1126\"}},\"id\":\"1122\",\"type\":\"BoxZoomTool\"}],\"root_ids\":[\"1101\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"0f9ccc63-4d75-43cf-9c97-238d5f541f58\",\"root_ids\":[\"1101\"],\"roots\":{\"1101\":\"9180fc6d-d040-4e48-938c-d3b5c4424102\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1101"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "#画布\n",
    "p = figure(plot_width=400,plot_height=400,title=\"水平柱状图Demo\")\n",
    "\n",
    "#绘制\n",
    "p.hbar(\n",
    "    y=[1,2,3],\n",
    "    height=0.5,\n",
    "    left=0,\n",
    "    right=[1.5,2.5,3.7],\n",
    "    color=\"yellow\"\n",
    ")\n",
    "\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 柱状图Demo1(Fruit Counts)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"807a573e-9156-43f2-a566-92495e5e32f9\" data-root-id=\"1205\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"d8c29fc9-ed6a-4228-af4f-1fb6a1c22ee3\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1216\"}],\"center\":[{\"id\":\"1218\"},{\"id\":\"1222\"}],\"left\":[{\"id\":\"1219\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"1242\"}],\"title\":{\"id\":\"1206\"},\"toolbar\":{\"id\":\"1231\"},\"x_range\":{\"id\":\"1208\"},\"x_scale\":{\"id\":\"1212\"},\"y_range\":{\"id\":\"1210\"},\"y_scale\":{\"id\":\"1214\"}},\"id\":\"1205\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"count\",\"@counts\"]]},\"id\":\"1230\",\"type\":\"HoverTool\"},{\"attributes\":{\"axis\":{\"id\":\"1216\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1218\",\"type\":\"Grid\"},{\"attributes\":{\"formatter\":{\"id\":\"1264\"},\"ticker\":{\"id\":\"1220\"}},\"id\":\"1219\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1228\",\"type\":\"HelpTool\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1229\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1220\",\"type\":\"BasicTicker\"},{\"attributes\":{\"source\":{\"id\":\"1204\"}},\"id\":\"1243\",\"type\":\"CDSView\"},{\"attributes\":{\"overlay\":{\"id\":\"1229\"}},\"id\":\"1225\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"data\":{\"counts\":[5,3,4,2,4,6],\"x\":[\"Apples\",\"Pears\",\"Nectarines\",\"Plums\",\"Grapes\",\"Strawberries\"]},\"selected\":{\"id\":\"1268\"},\"selection_policy\":{\"id\":\"1267\"}},\"id\":\"1204\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1224\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"axis\":{\"id\":\"1219\"},\"dimension\":1,\"ticker\":null},\"id\":\"1222\",\"type\":\"Grid\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1223\"},{\"id\":\"1224\"},{\"id\":\"1225\"},{\"id\":\"1226\"},{\"id\":\"1227\"},{\"id\":\"1228\"},{\"id\":\"1230\"}]},\"id\":\"1231\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1217\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1241\",\"type\":\"VBar\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1240\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1262\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"factors\":[\"Apples\",\"Pears\",\"Nectarines\",\"Plums\",\"Grapes\",\"Strawberries\"]},\"id\":\"1208\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"1223\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1267\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"text\":\"Fruits Counts\"},\"id\":\"1206\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1227\",\"type\":\"ResetTool\"},{\"attributes\":{\"formatter\":{\"id\":\"1262\"},\"ticker\":{\"id\":\"1217\"}},\"id\":\"1216\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"1212\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"1214\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1268\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1264\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"start\":0},\"id\":\"1210\",\"type\":\"DataRange1d\"},{\"attributes\":{\"data_source\":{\"id\":\"1204\"},\"glyph\":{\"id\":\"1240\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1241\"},\"selection_glyph\":null,\"view\":{\"id\":\"1243\"}},\"id\":\"1242\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1226\",\"type\":\"SaveTool\"}],\"root_ids\":[\"1205\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"d8c29fc9-ed6a-4228-af4f-1fb6a1c22ee3\",\"root_ids\":[\"1205\"],\"roots\":{\"1205\":\"807a573e-9156-43f2-a566-92495e5e32f9\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1205"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.models import ColumnDataSource\n",
    "# 数据准备(名称和值)\n",
    "fruits = [\"Apples\",\"Pears\",\"Nectarines\",\"Plums\",\"Grapes\",\"Strawberries\"]\n",
    "counts = [5,3,4,2,4,6]\n",
    "\n",
    "# 数据源准备\n",
    "source=ColumnDataSource(\n",
    "    data = dict(\n",
    "    x=fruits,\n",
    "    counts = counts\n",
    "    )\n",
    ")\n",
    "\n",
    "TOOLTIPS = [\n",
    "    (\"count\",\"@counts\")\n",
    "]\n",
    "\n",
    "# 画布\n",
    "p = figure(\n",
    "    x_range=fruits,\n",
    "    plot_height=350,\n",
    "    title=\"Fruits Counts\",\n",
    "    tooltips=TOOLTIPS,\n",
    ")\n",
    "\n",
    "# 绘制\n",
    "p.vbar(x='x',top='counts',width=0.8,source=source)\n",
    "p.xgrid.grid_line_color=None\n",
    "p.y_range.start=0\n",
    "\n",
    "#图例显示\n",
    "#p.legend.\n",
    "\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 实践（1）2019年7月常见可视化工具Github标星数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"33653bce-560d-4a97-b799-7963c0587a83\" data-root-id=\"1317\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"c1c18292-8b2f-4e84-83fd-7bdfd498ff50\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1328\"}],\"center\":[{\"id\":\"1330\"},{\"id\":\"1334\"}],\"left\":[{\"id\":\"1331\"}],\"renderers\":[{\"id\":\"1352\"}],\"title\":{\"id\":\"1318\"},\"toolbar\":{\"id\":\"1342\"},\"x_range\":{\"id\":\"1320\"},\"x_scale\":{\"id\":\"1324\"},\"y_range\":{\"id\":\"1322\"},\"y_scale\":{\"id\":\"1326\"}},\"id\":\"1317\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"source\":{\"id\":\"1349\"}},\"id\":\"1353\",\"type\":\"CDSView\"},{\"attributes\":{\"fill_color\":{\"field\":\"fill_color\"},\"line_color\":{\"field\":\"line_color\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1350\",\"type\":\"VBar\"},{\"attributes\":{\"factors\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"id\":\"1320\",\"type\":\"FactorRange\"},{\"attributes\":{\"start\":0},\"id\":\"1322\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1385\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1326\",\"type\":\"LinearScale\"},{\"attributes\":{\"axis\":{\"id\":\"1328\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1330\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1382\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"1386\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1380\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"formatter\":{\"id\":\"1380\"},\"ticker\":{\"id\":\"1329\"}},\"id\":\"1328\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1341\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1340\",\"type\":\"HelpTool\"},{\"attributes\":{\"overlay\":{\"id\":\"1341\"}},\"id\":\"1337\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"data\":{\"fill_color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"line_color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"top\":[9678,11034,5387,6038,4928,3783],\"x\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"selected\":{\"id\":\"1386\"},\"selection_policy\":{\"id\":\"1385\"}},\"id\":\"1349\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1338\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1339\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1336\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"text\":\"2019\\u5e747\\u6708\\u5e38\\u89c1\\u53ef\\u89c6\\u5316\\u5de5\\u5177Github\\u6807\\u661f\\u6570\\u91cf\"},\"id\":\"1318\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1329\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"data_source\":{\"id\":\"1349\"},\"glyph\":{\"id\":\"1350\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1351\"},\"selection_glyph\":null,\"view\":{\"id\":\"1353\"}},\"id\":\"1352\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1335\"},{\"id\":\"1336\"},{\"id\":\"1337\"},{\"id\":\"1338\"},{\"id\":\"1339\"},{\"id\":\"1340\"}]},\"id\":\"1342\",\"type\":\"Toolbar\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"fill_color\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"field\":\"line_color\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1351\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1332\",\"type\":\"BasicTicker\"},{\"attributes\":{\"formatter\":{\"id\":\"1382\"},\"ticker\":{\"id\":\"1332\"}},\"id\":\"1331\",\"type\":\"LinearAxis\"},{\"attributes\":{\"axis\":{\"id\":\"1331\"},\"dimension\":1,\"ticker\":null},\"id\":\"1334\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1335\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1324\",\"type\":\"CategoricalScale\"}],\"root_ids\":[\"1317\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"c1c18292-8b2f-4e84-83fd-7bdfd498ff50\",\"root_ids\":[\"1317\"],\"roots\":{\"1317\":\"33653bce-560d-4a97-b799-7963c0587a83\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1317"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.models import ColumnDataSource\n",
    "from bokeh.palettes import Spectral6\n",
    "import pandas as pd\n",
    "df=pd.read_csv('data/visualization-20190505.csv')\n",
    "p = figure(x_range=df['Visualization_tools'],title=\"2019年7月常见可视化工具Github标星数量\")\n",
    "p.vbar(x=df['Visualization_tools'], top=df['Star'] , width=0.8, color=Spectral6) \n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 学生实践：基本柱状图"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"f51029f2-4413-4177-81b7-491c49df73bf\" data-root-id=\"1435\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"7d32f48a-4013-4770-ae0b-45ded162f790\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1446\"}],\"center\":[{\"id\":\"1448\"},{\"id\":\"1452\"}],\"left\":[{\"id\":\"1449\"}],\"renderers\":[{\"id\":\"1470\"}],\"title\":{\"id\":\"1436\"},\"toolbar\":{\"id\":\"1460\"},\"x_range\":{\"id\":\"1438\"},\"x_scale\":{\"id\":\"1442\"},\"y_range\":{\"id\":\"1440\"},\"y_scale\":{\"id\":\"1444\"}},\"id\":\"1435\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"1442\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"1447\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"formatter\":{\"id\":\"1506\"},\"ticker\":{\"id\":\"1447\"}},\"id\":\"1446\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"1508\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"source\":{\"id\":\"1467\"}},\"id\":\"1471\",\"type\":\"CDSView\"},{\"attributes\":{\"formatter\":{\"id\":\"1508\"},\"ticker\":{\"id\":\"1450\"}},\"id\":\"1449\",\"type\":\"LinearAxis\"},{\"attributes\":{\"text\":\"2019\\u5e747\\u6708\\u5e38\\u89c1\\u53ef\\u89c6\\u5316\\u5de5\\u5177Github\\u63d0\\u4ea4\\u6b21\\u6570\"},\"id\":\"1436\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"1512\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1454\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1511\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"fill_color\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"field\":\"line_color\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1469\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1458\",\"type\":\"HelpTool\"},{\"attributes\":{\"factors\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"id\":\"1438\",\"type\":\"FactorRange\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1459\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"overlay\":{\"id\":\"1459\"}},\"id\":\"1455\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"start\":0},\"id\":\"1440\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1453\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1450\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"1446\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1448\",\"type\":\"Grid\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1453\"},{\"id\":\"1454\"},{\"id\":\"1455\"},{\"id\":\"1456\"},{\"id\":\"1457\"},{\"id\":\"1458\"}]},\"id\":\"1460\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1506\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"axis\":{\"id\":\"1449\"},\"dimension\":1,\"ticker\":null},\"id\":\"1452\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1444\",\"type\":\"LinearScale\"},{\"attributes\":{\"fill_color\":{\"field\":\"fill_color\"},\"line_color\":{\"field\":\"line_color\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1468\",\"type\":\"VBar\"},{\"attributes\":{\"data_source\":{\"id\":\"1467\"},\"glyph\":{\"id\":\"1468\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1469\"},\"selection_glyph\":null,\"view\":{\"id\":\"1471\"}},\"id\":\"1470\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"data\":{\"fill_color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"line_color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"top\":[29503,17673,1321,2316,3370,4286],\"x\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"selected\":{\"id\":\"1512\"},\"selection_policy\":{\"id\":\"1511\"}},\"id\":\"1467\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1457\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1456\",\"type\":\"SaveTool\"}],\"root_ids\":[\"1435\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"7d32f48a-4013-4770-ae0b-45ded162f790\",\"root_ids\":[\"1435\"],\"roots\":{\"1435\":\"f51029f2-4413-4177-81b7-491c49df73bf\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1435"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.models import ColumnDataSource\n",
    "from bokeh.palettes import Spectral6\n",
    "import pandas as pd\n",
    "df=pd.read_csv('data/visualization-20190505.csv')\n",
    "p = figure(x_range=df['Visualization_tools'],title=\"2019年7月常见可视化工具Github提交次数\")\n",
    "p.vbar(x=df['Visualization_tools'], top=df['Commits'] , width=0.8, color=Spectral6) \n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"4ef6c24a-bf37-49d6-9d7c-3144e672d428\" data-root-id=\"1561\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"abc91734-e9d1-4237-96ea-1584e52b888b\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1572\"}],\"center\":[{\"id\":\"1574\"},{\"id\":\"1578\"}],\"left\":[{\"id\":\"1575\"}],\"renderers\":[{\"id\":\"1596\"}],\"title\":{\"id\":\"1562\"},\"toolbar\":{\"id\":\"1586\"},\"x_range\":{\"id\":\"1564\"},\"x_scale\":{\"id\":\"1568\"},\"y_range\":{\"id\":\"1566\"},\"y_scale\":{\"id\":\"1570\"}},\"id\":\"1561\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1579\"},{\"id\":\"1580\"},{\"id\":\"1581\"},{\"id\":\"1582\"},{\"id\":\"1583\"},{\"id\":\"1584\"}]},\"id\":\"1586\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"1579\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1568\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"overlay\":{\"id\":\"1585\"}},\"id\":\"1581\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"text\":\"2019\\u5e747\\u6708\\u5e38\\u89c1\\u53ef\\u89c6\\u5316\\u5de5\\u5177Github\\u8d21\\u732e\\u8005\\u4eba\\u6570\"},\"id\":\"1562\",\"type\":\"Title\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"fill_color\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"field\":\"line_color\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1595\",\"type\":\"VBar\"},{\"attributes\":{\"factors\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"id\":\"1564\",\"type\":\"FactorRange\"},{\"attributes\":{},\"id\":\"1570\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"1573\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"formatter\":{\"id\":\"1642\"},\"ticker\":{\"id\":\"1576\"}},\"id\":\"1575\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1640\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{},\"id\":\"1576\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1582\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"1645\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"formatter\":{\"id\":\"1640\"},\"ticker\":{\"id\":\"1573\"}},\"id\":\"1572\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"fill_color\":{\"field\":\"fill_color\"},\"line_color\":{\"field\":\"line_color\"},\"top\":{\"field\":\"top\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"x\"}},\"id\":\"1594\",\"type\":\"VBar\"},{\"attributes\":{\"axis\":{\"id\":\"1572\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1574\",\"type\":\"Grid\"},{\"attributes\":{\"start\":0},\"id\":\"1566\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1642\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"data\":{\"fill_color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"line_color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"top\":[808,357,18,98,76,184],\"x\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"selected\":{\"id\":\"1646\"},\"selection_policy\":{\"id\":\"1645\"}},\"id\":\"1593\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1580\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"axis\":{\"id\":\"1575\"},\"dimension\":1,\"ticker\":null},\"id\":\"1578\",\"type\":\"Grid\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1585\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"data_source\":{\"id\":\"1593\"},\"glyph\":{\"id\":\"1594\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1595\"},\"selection_glyph\":null,\"view\":{\"id\":\"1597\"}},\"id\":\"1596\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1646\",\"type\":\"Selection\"},{\"attributes\":{\"source\":{\"id\":\"1593\"}},\"id\":\"1597\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1584\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1583\",\"type\":\"ResetTool\"}],\"root_ids\":[\"1561\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"abc91734-e9d1-4237-96ea-1584e52b888b\",\"root_ids\":[\"1561\"],\"roots\":{\"1561\":\"4ef6c24a-bf37-49d6-9d7c-3144e672d428\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1561"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.models import ColumnDataSource\n",
    "from bokeh.palettes import Spectral6\n",
    "import pandas as pd\n",
    "df=pd.read_csv('data/visualization-20190505.csv')\n",
    "p = figure(x_range=df['Visualization_tools'],title=\"2019年7月常见可视化工具Github贡献者人数\")\n",
    "p.vbar(x=df['Visualization_tools'], top=df['Contributors'] , width=0.8, color=Spectral6) \n",
    "p.xgrid.grid_line_color = None\n",
    "p.y_range.start = 0\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0     9678\n",
       "1    11034\n",
       "2     5387\n",
       "3     6038\n",
       "4     4928\n",
       "5     3783\n",
       "Name: Star, dtype: int64"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['Star']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "BokehDeprecationWarning: 'legend' keyword is deprecated, use explicit 'legend_label', 'legend_field', or 'legend_group' keywords instead\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"5bc3dc87-5aa0-464e-a0bc-23e85789875d\" data-root-id=\"1696\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"0a765bbe-820e-4f60-93a8-f9606127959b\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1707\"}],\"center\":[{\"id\":\"1709\"},{\"id\":\"1713\"},{\"id\":\"1743\"}],\"left\":[{\"id\":\"1710\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"1733\"}],\"title\":{\"id\":\"1697\"},\"toolbar\":{\"id\":\"1722\"},\"x_range\":{\"id\":\"1699\"},\"x_scale\":{\"id\":\"1703\"},\"y_range\":{\"id\":\"1701\"},\"y_scale\":{\"id\":\"1705\"}},\"id\":\"1696\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"end\":14000,\"start\":0},\"id\":\"1701\",\"type\":\"DataRange1d\"},{\"attributes\":{\"data\":{\"color\":[\"#3288bd\",\"#99d594\",\"#e6f598\",\"#fee08b\",\"#fc8d59\",\"#d53e4f\"],\"star_counts\":[9678,11034,5387,6038,4928,3783],\"tools\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"selected\":{\"id\":\"1742\"},\"selection_policy\":{\"id\":\"1741\"}},\"id\":\"1695\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"1705\",\"type\":\"LinearScale\"},{\"attributes\":{\"fill_color\":{\"field\":\"color\"},\"line_color\":{\"field\":\"color\"},\"top\":{\"field\":\"star_counts\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"tools\"}},\"id\":\"1731\",\"type\":\"VBar\"},{\"attributes\":{\"formatter\":{\"id\":\"1736\"},\"ticker\":{\"id\":\"1708\"}},\"id\":\"1707\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"1715\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"axis\":{\"id\":\"1710\"},\"dimension\":1,\"ticker\":null},\"id\":\"1713\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1708\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"color\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"field\":\"color\"},\"top\":{\"field\":\"star_counts\"},\"width\":{\"value\":0.8},\"x\":{\"field\":\"tools\"}},\"id\":\"1732\",\"type\":\"VBar\"},{\"attributes\":{\"axis\":{\"id\":\"1707\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1709\",\"type\":\"Grid\"},{\"attributes\":{\"text\":\"2019 Visualization tools star \"},\"id\":\"1697\",\"type\":\"Title\"},{\"attributes\":{\"factors\":[\"matplotlib\",\"bokeh\",\"pyecharts\",\"seaborn\",\"plotly\",\"ggplot2\"]},\"id\":\"1699\",\"type\":\"FactorRange\"},{\"attributes\":{\"data_source\":{\"id\":\"1695\"},\"glyph\":{\"id\":\"1731\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1732\"},\"selection_glyph\":null,\"view\":{\"id\":\"1734\"}},\"id\":\"1733\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"1718\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"1719\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1711\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"1738\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"items\":[{\"id\":\"1744\"}],\"location\":\"top_center\",\"orientation\":\"horizontal\"},\"id\":\"1743\",\"type\":\"Legend\"},{\"attributes\":{\"source\":{\"id\":\"1695\"}},\"id\":\"1734\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"1741\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"1717\",\"type\":\"SaveTool\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1714\"},{\"id\":\"1715\"},{\"id\":\"1716\"},{\"id\":\"1717\"},{\"id\":\"1718\"},{\"id\":\"1719\"},{\"id\":\"1721\"}]},\"id\":\"1722\",\"type\":\"Toolbar\"},{\"attributes\":{\"label\":{\"field\":\"tools\"},\"renderers\":[{\"id\":\"1733\"}]},\"id\":\"1744\",\"type\":\"LegendItem\"},{\"attributes\":{},\"id\":\"1742\",\"type\":\"Selection\"},{\"attributes\":{\"formatter\":{\"id\":\"1738\"},\"ticker\":{\"id\":\"1711\"}},\"id\":\"1710\",\"type\":\"LinearAxis\"},{\"attributes\":{\"overlay\":{\"id\":\"1720\"}},\"id\":\"1716\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1720\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"star\",\"@star_counts\"],[\"tools\",\"@tools\"]]},\"id\":\"1721\",\"type\":\"HoverTool\"},{\"attributes\":{},\"id\":\"1736\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{},\"id\":\"1703\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"1714\",\"type\":\"PanTool\"}],\"root_ids\":[\"1696\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"0a765bbe-820e-4f60-93a8-f9606127959b\",\"root_ids\":[\"1696\"],\"roots\":{\"1696\":\"5bc3dc87-5aa0-464e-a0bc-23e85789875d\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1696"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.palettes import Spectral6\n",
    "\n",
    "# 数据源准备\n",
    "source=ColumnDataSource(\n",
    "    data = dict(\n",
    "    tools=df['Visualization_tools'],\n",
    "    star_counts = df['Star'],\n",
    "    color=Spectral6 #坑，颜色也应该存进source\n",
    "    )\n",
    ")\n",
    "\n",
    "TOOLTIPS = [\n",
    "    (\"star\",\"@star_counts\"),\n",
    "    (\"tools\",\"@tools\")\n",
    "]\n",
    "\n",
    "# 画布\n",
    "p = figure(\n",
    "    x_range=df['Visualization_tools'],\n",
    "    plot_height=350,\n",
    "    title=\"2019 Visualization tools star \",\n",
    "    tooltips=TOOLTIPS,\n",
    ")\n",
    "\n",
    "# 绘制\n",
    "p.vbar(x='tools',top='star_counts',width=0.8,source=source,color='color',legend='tools')\n",
    "p.xgrid.grid_line_color=None\n",
    "p.y_range.start=0\n",
    "\n",
    "# 加图例\n",
    "p.legend.location = \"top_center\"\n",
    "p.legend.orientation = \"horizontal\"\n",
    "p.y_range.end = 14000\n",
    "\n",
    "\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 三组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Watch', 'Fork', 'Contributors']"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "group1 = [df.columns.tolist()[1],df.columns.tolist()[3],df.columns.tolist()[5]]\n",
    "group1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(533, 4143, 808, 396, 2526, 357, 263, 1148, 18, 234, 970, 98, 234, 1114, 76, 329, 1427, 184)\n"
     ]
    }
   ],
   "source": [
    "counts_1 = sum(zip(df['Watch'], df['Fork'], df['Contributors']), ())\n",
    "print(counts_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('matplotlib', 'Watch'),\n",
       " ('matplotlib', 'Fork'),\n",
       " ('matplotlib', 'Contributors'),\n",
       " ('bokeh', 'Watch'),\n",
       " ('bokeh', 'Fork'),\n",
       " ('bokeh', 'Contributors'),\n",
       " ('pyecharts', 'Watch'),\n",
       " ('pyecharts', 'Fork'),\n",
       " ('pyecharts', 'Contributors'),\n",
       " ('seaborn', 'Watch'),\n",
       " ('seaborn', 'Fork'),\n",
       " ('seaborn', 'Contributors'),\n",
       " ('plotly', 'Watch'),\n",
       " ('plotly', 'Fork'),\n",
       " ('plotly', 'Contributors'),\n",
       " ('ggplot2', 'Watch'),\n",
       " ('ggplot2', 'Fork'),\n",
       " ('ggplot2', 'Contributors')]"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = [ (tool, categroy) for tool in tools for categroy in group1 ]\n",
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [],
   "source": [
    "source = ColumnDataSource(data=dict(x=x, counts=counts_1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"d72442e3-d806-44d6-82d4-b0ed8112ab40\" data-root-id=\"13394\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"5f5d54e6-2fa3-43ed-b0d3-4ae2ee923e67\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"13404\"}],\"center\":[{\"id\":\"13406\"},{\"id\":\"13410\"}],\"left\":[{\"id\":\"13407\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"13430\"}],\"title\":{\"id\":\"13395\"},\"toolbar\":{\"id\":\"13419\"},\"x_range\":{\"id\":\"13393\"},\"x_scale\":{\"id\":\"13400\"},\"y_range\":{\"id\":\"13398\"},\"y_scale\":{\"id\":\"13402\"}},\"id\":\"13394\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"formatter\":{\"id\":\"13772\"},\"major_label_orientation\":1,\"ticker\":{\"id\":\"13405\"}},\"id\":\"13404\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"13778\",\"type\":\"Selection\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"13411\"},{\"id\":\"13412\"},{\"id\":\"13413\"},{\"id\":\"13414\"},{\"id\":\"13415\"},{\"id\":\"13416\"},{\"id\":\"13418\"}]},\"id\":\"13419\",\"type\":\"Toolbar\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"13429\",\"type\":\"VBar\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"count\",\"@counts\"]]},\"id\":\"13418\",\"type\":\"HoverTool\"},{\"attributes\":{},\"id\":\"13774\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"source\":{\"id\":\"13392\"}},\"id\":\"13431\",\"type\":\"CDSView\"},{\"attributes\":{\"formatter\":{\"id\":\"13774\"},\"ticker\":{\"id\":\"13408\"}},\"id\":\"13407\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"13415\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"13405\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"13416\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"13400\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"13777\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"start\":0},\"id\":\"13398\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"13411\",\"type\":\"PanTool\"},{\"attributes\":{\"data_source\":{\"id\":\"13392\"},\"glyph\":{\"id\":\"13428\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"13429\"},\"selection_glyph\":null,\"view\":{\"id\":\"13431\"}},\"id\":\"13430\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"axis\":{\"id\":\"13407\"},\"dimension\":1,\"ticker\":null},\"id\":\"13410\",\"type\":\"Grid\"},{\"attributes\":{\"factors\":[[\"matplotlib\",\"Watch\"],[\"matplotlib\",\"Fork\"],[\"matplotlib\",\"Contributors\"],[\"bokeh\",\"Watch\"],[\"bokeh\",\"Fork\"],[\"bokeh\",\"Contributors\"],[\"pyecharts\",\"Watch\"],[\"pyecharts\",\"Fork\"],[\"pyecharts\",\"Contributors\"],[\"seaborn\",\"Watch\"],[\"seaborn\",\"Fork\"],[\"seaborn\",\"Contributors\"],[\"plotly\",\"Watch\"],[\"plotly\",\"Fork\"],[\"plotly\",\"Contributors\"],[\"ggplot2\",\"Watch\"],[\"ggplot2\",\"Fork\"],[\"ggplot2\",\"Contributors\"]],\"range_padding\":0.1},\"id\":\"13393\",\"type\":\"FactorRange\"},{\"attributes\":{\"text\":\"Fruit Counts by Year\"},\"id\":\"13395\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"13414\",\"type\":\"SaveTool\"},{\"attributes\":{\"data\":{\"counts\":[533,4143,808,396,2526,357,263,1148,18,234,970,98,234,1114,76,329,1427,184],\"x\":[[\"matplotlib\",\"Watch\"],[\"matplotlib\",\"Fork\"],[\"matplotlib\",\"Contributors\"],[\"bokeh\",\"Watch\"],[\"bokeh\",\"Fork\"],[\"bokeh\",\"Contributors\"],[\"pyecharts\",\"Watch\"],[\"pyecharts\",\"Fork\"],[\"pyecharts\",\"Contributors\"],[\"seaborn\",\"Watch\"],[\"seaborn\",\"Fork\"],[\"seaborn\",\"Contributors\"],[\"plotly\",\"Watch\"],[\"plotly\",\"Fork\"],[\"plotly\",\"Contributors\"],[\"ggplot2\",\"Watch\"],[\"ggplot2\",\"Fork\"],[\"ggplot2\",\"Contributors\"]]},\"selected\":{\"id\":\"13778\"},\"selection_policy\":{\"id\":\"13777\"}},\"id\":\"13392\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"13772\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{},\"id\":\"13402\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"13412\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"overlay\":{\"id\":\"13417\"}},\"id\":\"13413\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"13417\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"axis\":{\"id\":\"13404\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"13406\",\"type\":\"Grid\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"13428\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"13408\",\"type\":\"BasicTicker\"}],\"root_ids\":[\"13394\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"5f5d54e6-2fa3-43ed-b0d3-4ae2ee923e67\",\"root_ids\":[\"13394\"],\"roots\":{\"13394\":\"d72442e3-d806-44d6-82d4-b0ed8112ab40\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "13394"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "TOOLTIPS = [\n",
    "    (\"count\",\"@counts\"),\n",
    "\n",
    "]\n",
    "\n",
    "\n",
    "# 画布\n",
    "p = figure(x_range=FactorRange(*x), plot_height=350, title=\"Fruit Counts by Year\",\n",
    "           tooltips=TOOLTIPS\n",
    "#            toolbar_location=None, tools=\"\"\n",
    "          )\n",
    "# 柱状图\n",
    "p.vbar(x='x', top='counts', width=0.9, source=source)\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xaxis.major_label_orientation = 1\n",
    "p.xgrid.grid_line_color = None\n",
    "\n",
    "\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"30b42b7e-228a-4309-a9f1-3b02a37a3a6b\" data-root-id=\"13394\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"601a276f-40ef-4958-9518-806a3ea1c9dd\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"13404\"}],\"center\":[{\"id\":\"13406\"},{\"id\":\"13410\"}],\"left\":[{\"id\":\"13407\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"13430\"},{\"id\":\"13831\"}],\"title\":{\"id\":\"13395\"},\"toolbar\":{\"id\":\"13419\"},\"x_range\":{\"id\":\"13393\"},\"x_scale\":{\"id\":\"13400\"},\"y_range\":{\"id\":\"13398\"},\"y_scale\":{\"id\":\"13402\"}},\"id\":\"13394\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"x\",\"transform\":{\"id\":\"13827\"}},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"13830\",\"type\":\"VBar\"},{\"attributes\":{\"formatter\":{\"id\":\"13772\"},\"major_label_orientation\":1,\"ticker\":{\"id\":\"13405\"}},\"id\":\"13404\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"13778\",\"type\":\"Selection\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"13411\"},{\"id\":\"13412\"},{\"id\":\"13413\"},{\"id\":\"13414\"},{\"id\":\"13415\"},{\"id\":\"13416\"},{\"id\":\"13418\"}]},\"id\":\"13419\",\"type\":\"Toolbar\"},{\"attributes\":{\"fill_color\":{\"field\":\"x\",\"transform\":{\"id\":\"13827\"}},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"13829\",\"type\":\"VBar\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"13429\",\"type\":\"VBar\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"count\",\"@counts\"]]},\"id\":\"13418\",\"type\":\"HoverTool\"},{\"attributes\":{\"end\":2,\"factors\":[\"Star\",\"Commits\",\"Contributors\"],\"palette\":[\"#c9d9d3\",\"#718dbf\",\"#e84d60\"],\"start\":1},\"id\":\"13827\",\"type\":\"CategoricalColorMapper\"},{\"attributes\":{},\"id\":\"13774\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"source\":{\"id\":\"13392\"}},\"id\":\"13431\",\"type\":\"CDSView\"},{\"attributes\":{\"formatter\":{\"id\":\"13774\"},\"ticker\":{\"id\":\"13408\"}},\"id\":\"13407\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"13415\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"13405\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"13416\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"13400\",\"type\":\"CategoricalScale\"},{\"attributes\":{},\"id\":\"13777\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"start\":0},\"id\":\"13398\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"13411\",\"type\":\"PanTool\"},{\"attributes\":{\"data_source\":{\"id\":\"13392\"},\"glyph\":{\"id\":\"13428\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"13429\"},\"selection_glyph\":null,\"view\":{\"id\":\"13431\"}},\"id\":\"13430\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"axis\":{\"id\":\"13407\"},\"dimension\":1,\"ticker\":null},\"id\":\"13410\",\"type\":\"Grid\"},{\"attributes\":{\"factors\":[[\"matplotlib\",\"Watch\"],[\"matplotlib\",\"Fork\"],[\"matplotlib\",\"Contributors\"],[\"bokeh\",\"Watch\"],[\"bokeh\",\"Fork\"],[\"bokeh\",\"Contributors\"],[\"pyecharts\",\"Watch\"],[\"pyecharts\",\"Fork\"],[\"pyecharts\",\"Contributors\"],[\"seaborn\",\"Watch\"],[\"seaborn\",\"Fork\"],[\"seaborn\",\"Contributors\"],[\"plotly\",\"Watch\"],[\"plotly\",\"Fork\"],[\"plotly\",\"Contributors\"],[\"ggplot2\",\"Watch\"],[\"ggplot2\",\"Fork\"],[\"ggplot2\",\"Contributors\"]],\"range_padding\":0.1},\"id\":\"13393\",\"type\":\"FactorRange\"},{\"attributes\":{\"text\":\"Fruit Counts by Year\"},\"id\":\"13395\",\"type\":\"Title\"},{\"attributes\":{\"data_source\":{\"id\":\"13392\"},\"glyph\":{\"id\":\"13829\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"13830\"},\"selection_glyph\":null,\"view\":{\"id\":\"13832\"}},\"id\":\"13831\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"13414\",\"type\":\"SaveTool\"},{\"attributes\":{\"data\":{\"counts\":[533,4143,808,396,2526,357,263,1148,18,234,970,98,234,1114,76,329,1427,184],\"x\":[[\"matplotlib\",\"Watch\"],[\"matplotlib\",\"Fork\"],[\"matplotlib\",\"Contributors\"],[\"bokeh\",\"Watch\"],[\"bokeh\",\"Fork\"],[\"bokeh\",\"Contributors\"],[\"pyecharts\",\"Watch\"],[\"pyecharts\",\"Fork\"],[\"pyecharts\",\"Contributors\"],[\"seaborn\",\"Watch\"],[\"seaborn\",\"Fork\"],[\"seaborn\",\"Contributors\"],[\"plotly\",\"Watch\"],[\"plotly\",\"Fork\"],[\"plotly\",\"Contributors\"],[\"ggplot2\",\"Watch\"],[\"ggplot2\",\"Fork\"],[\"ggplot2\",\"Contributors\"]]},\"selected\":{\"id\":\"13778\"},\"selection_policy\":{\"id\":\"13777\"}},\"id\":\"13392\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"13772\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{},\"id\":\"13402\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"13412\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"source\":{\"id\":\"13392\"}},\"id\":\"13832\",\"type\":\"CDSView\"},{\"attributes\":{\"overlay\":{\"id\":\"13417\"}},\"id\":\"13413\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"13417\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"axis\":{\"id\":\"13404\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"13406\",\"type\":\"Grid\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"13428\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"13408\",\"type\":\"BasicTicker\"}],\"root_ids\":[\"13394\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"601a276f-40ef-4958-9518-806a3ea1c9dd\",\"root_ids\":[\"13394\"],\"roots\":{\"13394\":\"30b42b7e-228a-4309-a9f1-3b02a37a3a6b\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "13394"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "## 增加分组柱状图颜色\n",
    "from bokeh.transform import factor_cmap\n",
    "\n",
    "palette = [\"#c9d9d3\", \"#718dbf\", \"#e84d60\"]\n",
    "\n",
    "# 绘图\n",
    "p.vbar(x='x', top='counts', width=0.9, source=source, line_color=\"white\",\n",
    "       fill_color=factor_cmap('x', palette=palette, factors=group, start=1, end=2))\n",
    "\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xaxis.major_label_orientation = 1\n",
    "p.xgrid.grid_line_color = None\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 两组"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Star', 'Commits']"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "group2 = [df.columns.tolist()[2],df.columns.tolist()[4]]\n",
    "group2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(9678, 29503, 11034, 17673, 5387, 1321, 6038, 2316, 4928, 3370, 3783, 4286)\n"
     ]
    }
   ],
   "source": [
    "counts_2 = sum(zip(df['Star'], df['Commits']), ())\n",
    "print(counts_2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('matplotlib', 'Star'),\n",
       " ('matplotlib', 'Commits'),\n",
       " ('bokeh', 'Star'),\n",
       " ('bokeh', 'Commits'),\n",
       " ('pyecharts', 'Star'),\n",
       " ('pyecharts', 'Commits'),\n",
       " ('seaborn', 'Star'),\n",
       " ('seaborn', 'Commits'),\n",
       " ('plotly', 'Star'),\n",
       " ('plotly', 'Commits'),\n",
       " ('ggplot2', 'Star'),\n",
       " ('ggplot2', 'Commits')]"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = [ (tool, categroy) for tool in tools for categroy in group2 ]\n",
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [],
   "source": [
    "source = ColumnDataSource(data=dict(x=x, counts=counts_2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"115895cd-f074-409c-aeb1-f7aef35bbd31\" data-root-id=\"11762\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"71f4056b-c158-455f-9b9a-d2075510a658\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"11772\"}],\"center\":[{\"id\":\"11774\"},{\"id\":\"11778\"}],\"left\":[{\"id\":\"11775\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"11798\"}],\"title\":{\"id\":\"11763\"},\"toolbar\":{\"id\":\"11787\"},\"x_range\":{\"id\":\"11761\"},\"x_scale\":{\"id\":\"11768\"},\"y_range\":{\"id\":\"11766\"},\"y_scale\":{\"id\":\"11770\"}},\"id\":\"11762\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"text\":\"Fruit Counts by Year\"},\"id\":\"11763\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"11776\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"12122\",\"type\":\"Selection\"},{\"attributes\":{\"data_source\":{\"id\":\"11760\"},\"glyph\":{\"id\":\"11796\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"11797\"},\"selection_glyph\":null,\"view\":{\"id\":\"11799\"}},\"id\":\"11798\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"11768\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"data\":{\"counts\":[9678,29503,11034,17673,5387,1321,6038,2316,4928,3370,3783,4286],\"x\":[[\"matplotlib\",\"Star\"],[\"matplotlib\",\"Commits\"],[\"bokeh\",\"Star\"],[\"bokeh\",\"Commits\"],[\"pyecharts\",\"Star\"],[\"pyecharts\",\"Commits\"],[\"seaborn\",\"Star\"],[\"seaborn\",\"Commits\"],[\"plotly\",\"Star\"],[\"plotly\",\"Commits\"],[\"ggplot2\",\"Star\"],[\"ggplot2\",\"Commits\"]]},\"selected\":{\"id\":\"12122\"},\"selection_policy\":{\"id\":\"12121\"}},\"id\":\"11760\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"axis\":{\"id\":\"11775\"},\"dimension\":1,\"ticker\":null},\"id\":\"11778\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"12121\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"12116\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{},\"id\":\"11773\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"axis\":{\"id\":\"11772\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"11774\",\"type\":\"Grid\"},{\"attributes\":{\"formatter\":{\"id\":\"12116\"},\"major_label_orientation\":1,\"ticker\":{\"id\":\"11773\"}},\"id\":\"11772\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"11779\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"11770\",\"type\":\"LinearScale\"},{\"attributes\":{\"formatter\":{\"id\":\"12118\"},\"ticker\":{\"id\":\"11776\"}},\"id\":\"11775\",\"type\":\"LinearAxis\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"11797\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"11782\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"11784\",\"type\":\"HelpTool\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"11779\"},{\"id\":\"11780\"},{\"id\":\"11781\"},{\"id\":\"11782\"},{\"id\":\"11783\"},{\"id\":\"11784\"},{\"id\":\"11786\"}]},\"id\":\"11787\",\"type\":\"Toolbar\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"11796\",\"type\":\"VBar\"},{\"attributes\":{\"source\":{\"id\":\"11760\"}},\"id\":\"11799\",\"type\":\"CDSView\"},{\"attributes\":{\"factors\":[[\"matplotlib\",\"Star\"],[\"matplotlib\",\"Commits\"],[\"bokeh\",\"Star\"],[\"bokeh\",\"Commits\"],[\"pyecharts\",\"Star\"],[\"pyecharts\",\"Commits\"],[\"seaborn\",\"Star\"],[\"seaborn\",\"Commits\"],[\"plotly\",\"Star\"],[\"plotly\",\"Commits\"],[\"ggplot2\",\"Star\"],[\"ggplot2\",\"Commits\"]],\"range_padding\":0.1},\"id\":\"11761\",\"type\":\"FactorRange\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"11785\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"overlay\":{\"id\":\"11785\"}},\"id\":\"11781\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"count\",\"@counts\"]]},\"id\":\"11786\",\"type\":\"HoverTool\"},{\"attributes\":{},\"id\":\"12118\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"11780\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"start\":0},\"id\":\"11766\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"11783\",\"type\":\"ResetTool\"}],\"root_ids\":[\"11762\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"71f4056b-c158-455f-9b9a-d2075510a658\",\"root_ids\":[\"11762\"],\"roots\":{\"11762\":\"115895cd-f074-409c-aeb1-f7aef35bbd31\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "11762"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "TOOLTIPS = [\n",
    "    (\"count\",\"@counts\"),\n",
    "]\n",
    "\n",
    "# 画布\n",
    "p = figure(x_range=FactorRange(*x), plot_height=350, title=\"Fruit Counts by Year\",\n",
    "           tooltips=TOOLTIPS\n",
    "#            toolbar_location=None, tools=\"\"\n",
    "          )\n",
    "# 柱状图\n",
    "p.vbar(x='x', top='counts', width=0.9, source=source)\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xaxis.major_label_orientation = 1\n",
    "p.xgrid.grid_line_color = None\n",
    "\n",
    "\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"f92c38b4-4d74-49ad-9dc7-552cf4b6bb72\" data-root-id=\"11762\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"5cb53d45-84c3-4f3a-a0ec-28d15901e3f9\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"11772\"}],\"center\":[{\"id\":\"11774\"},{\"id\":\"11778\"}],\"left\":[{\"id\":\"11775\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"11798\"},{\"id\":\"12175\"}],\"title\":{\"id\":\"11763\"},\"toolbar\":{\"id\":\"11787\"},\"x_range\":{\"id\":\"11761\"},\"x_scale\":{\"id\":\"11768\"},\"y_range\":{\"id\":\"11766\"},\"y_scale\":{\"id\":\"11770\"}},\"id\":\"11762\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"text\":\"Fruit Counts by Year\"},\"id\":\"11763\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"11776\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"12122\",\"type\":\"Selection\"},{\"attributes\":{\"data_source\":{\"id\":\"11760\"},\"glyph\":{\"id\":\"11796\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"11797\"},\"selection_glyph\":null,\"view\":{\"id\":\"11799\"}},\"id\":\"11798\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"11768\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"data\":{\"counts\":[9678,29503,11034,17673,5387,1321,6038,2316,4928,3370,3783,4286],\"x\":[[\"matplotlib\",\"Star\"],[\"matplotlib\",\"Commits\"],[\"bokeh\",\"Star\"],[\"bokeh\",\"Commits\"],[\"pyecharts\",\"Star\"],[\"pyecharts\",\"Commits\"],[\"seaborn\",\"Star\"],[\"seaborn\",\"Commits\"],[\"plotly\",\"Star\"],[\"plotly\",\"Commits\"],[\"ggplot2\",\"Star\"],[\"ggplot2\",\"Commits\"]]},\"selected\":{\"id\":\"12122\"},\"selection_policy\":{\"id\":\"12121\"}},\"id\":\"11760\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"axis\":{\"id\":\"11775\"},\"dimension\":1,\"ticker\":null},\"id\":\"11778\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"12121\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"12116\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"fill_color\":{\"field\":\"x\",\"transform\":{\"id\":\"12171\"}},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"12173\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"11773\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"axis\":{\"id\":\"11772\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"11774\",\"type\":\"Grid\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"x\",\"transform\":{\"id\":\"12171\"}},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"12174\",\"type\":\"VBar\"},{\"attributes\":{\"formatter\":{\"id\":\"12116\"},\"major_label_orientation\":1,\"ticker\":{\"id\":\"11773\"}},\"id\":\"11772\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"11779\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"11770\",\"type\":\"LinearScale\"},{\"attributes\":{\"formatter\":{\"id\":\"12118\"},\"ticker\":{\"id\":\"11776\"}},\"id\":\"11775\",\"type\":\"LinearAxis\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"11797\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"11782\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"11784\",\"type\":\"HelpTool\"},{\"attributes\":{\"data_source\":{\"id\":\"11760\"},\"glyph\":{\"id\":\"12173\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"12174\"},\"selection_glyph\":null,\"view\":{\"id\":\"12176\"}},\"id\":\"12175\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"11779\"},{\"id\":\"11780\"},{\"id\":\"11781\"},{\"id\":\"11782\"},{\"id\":\"11783\"},{\"id\":\"11784\"},{\"id\":\"11786\"}]},\"id\":\"11787\",\"type\":\"Toolbar\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"11796\",\"type\":\"VBar\"},{\"attributes\":{\"source\":{\"id\":\"11760\"}},\"id\":\"11799\",\"type\":\"CDSView\"},{\"attributes\":{\"factors\":[[\"matplotlib\",\"Star\"],[\"matplotlib\",\"Commits\"],[\"bokeh\",\"Star\"],[\"bokeh\",\"Commits\"],[\"pyecharts\",\"Star\"],[\"pyecharts\",\"Commits\"],[\"seaborn\",\"Star\"],[\"seaborn\",\"Commits\"],[\"plotly\",\"Star\"],[\"plotly\",\"Commits\"],[\"ggplot2\",\"Star\"],[\"ggplot2\",\"Commits\"]],\"range_padding\":0.1},\"id\":\"11761\",\"type\":\"FactorRange\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"11785\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"overlay\":{\"id\":\"11785\"}},\"id\":\"11781\",\"type\":\"BoxZoomTool\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"count\",\"@counts\"]]},\"id\":\"11786\",\"type\":\"HoverTool\"},{\"attributes\":{\"source\":{\"id\":\"11760\"}},\"id\":\"12176\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"12118\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"11780\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"end\":2,\"factors\":[\"Star\",\"Commits\",\"Contributors\"],\"palette\":[\"#c9d9d3\",\"#718dbf\",\"#e84d60\"],\"start\":1},\"id\":\"12171\",\"type\":\"CategoricalColorMapper\"},{\"attributes\":{\"start\":0},\"id\":\"11766\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"11783\",\"type\":\"ResetTool\"}],\"root_ids\":[\"11762\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"5cb53d45-84c3-4f3a-a0ec-28d15901e3f9\",\"root_ids\":[\"11762\"],\"roots\":{\"11762\":\"f92c38b4-4d74-49ad-9dc7-552cf4b6bb72\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "11762"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "## 增加分组柱状图颜色\n",
    "from bokeh.transform import factor_cmap\n",
    "\n",
    "palette = [\"#c9d9d3\", \"#718dbf\", \"#e84d60\"]\n",
    "\n",
    "# 绘图\n",
    "p.vbar(x='x', top='counts', width=0.9, source=source, line_color=\"white\",\n",
    "       fill_color=factor_cmap('x', palette=palette, factors=group, start=1, end=2))\n",
    "\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xaxis.major_label_orientation = 1\n",
    "p.xgrid.grid_line_color = None\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 分组柱状图课后实践（star,commits,contributes）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Visualization_tools</th>\n",
       "      <th>Watch</th>\n",
       "      <th>Star</th>\n",
       "      <th>Fork</th>\n",
       "      <th>Commits</th>\n",
       "      <th>Contributors</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>matplotlib</td>\n",
       "      <td>533</td>\n",
       "      <td>9678</td>\n",
       "      <td>4143</td>\n",
       "      <td>29503</td>\n",
       "      <td>808</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>bokeh</td>\n",
       "      <td>396</td>\n",
       "      <td>11034</td>\n",
       "      <td>2526</td>\n",
       "      <td>17673</td>\n",
       "      <td>357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>pyecharts</td>\n",
       "      <td>263</td>\n",
       "      <td>5387</td>\n",
       "      <td>1148</td>\n",
       "      <td>1321</td>\n",
       "      <td>18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>seaborn</td>\n",
       "      <td>234</td>\n",
       "      <td>6038</td>\n",
       "      <td>970</td>\n",
       "      <td>2316</td>\n",
       "      <td>98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>plotly</td>\n",
       "      <td>234</td>\n",
       "      <td>4928</td>\n",
       "      <td>1114</td>\n",
       "      <td>3370</td>\n",
       "      <td>76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>ggplot2</td>\n",
       "      <td>329</td>\n",
       "      <td>3783</td>\n",
       "      <td>1427</td>\n",
       "      <td>4286</td>\n",
       "      <td>184</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Visualization_tools  Watch   Star  Fork  Commits  Contributors\n",
       "0          matplotlib    533   9678  4143    29503           808\n",
       "1               bokeh    396  11034  2526    17673           357\n",
       "2           pyecharts    263   5387  1148     1321            18\n",
       "3             seaborn    234   6038   970     2316            98\n",
       "4              plotly    234   4928  1114     3370            76\n",
       "5             ggplot2    329   3783  1427     4286           184"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "pd.read_csv('data/visualization-20190505.csv')\n",
    "df = pd.read_csv('data/visualization-20190505.csv')\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Visualization_tools', 'Watch', 'Star', 'Fork', 'Commits', 'Contributors']"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns.tolist()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Star', 'Commits', 'Contributors']"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "group = [df.columns.tolist()[2],df.columns.tolist()[4],df.columns.tolist()[5]]\n",
    "group"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    matplotlib\n",
       "1         bokeh\n",
       "2     pyecharts\n",
       "3       seaborn\n",
       "4        plotly\n",
       "5       ggplot2\n",
       "Name: Visualization_tools, dtype: object"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tools = df['Visualization_tools']\n",
    "tools"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[('matplotlib', 'Star'),\n",
       " ('matplotlib', 'Commits'),\n",
       " ('matplotlib', 'Contributors'),\n",
       " ('bokeh', 'Star'),\n",
       " ('bokeh', 'Commits'),\n",
       " ('bokeh', 'Contributors'),\n",
       " ('pyecharts', 'Star'),\n",
       " ('pyecharts', 'Commits'),\n",
       " ('pyecharts', 'Contributors'),\n",
       " ('seaborn', 'Star'),\n",
       " ('seaborn', 'Commits'),\n",
       " ('seaborn', 'Contributors'),\n",
       " ('plotly', 'Star'),\n",
       " ('plotly', 'Commits'),\n",
       " ('plotly', 'Contributors'),\n",
       " ('ggplot2', 'Star'),\n",
       " ('ggplot2', 'Commits'),\n",
       " ('ggplot2', 'Contributors')]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = [ (tool, categroy) for tool in tools for categroy in group ]\n",
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(9678, 29503, 808, 11034, 17673, 357, 5387, 1321, 18, 6038, 2316, 98, 4928, 3370, 76, 3783, 4286, 184)\n"
     ]
    }
   ],
   "source": [
    "counts = sum(zip(df['Star'], df['Commits'], df['Contributors']), ())\n",
    "print(counts)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "source = ColumnDataSource(data=dict(x=x, counts=counts))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"5b5e0a96-f3a0-4efe-89d8-a0723ea08163\" data-root-id=\"3375\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"e9e56532-60d9-4b78-a25e-51ad22290e27\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"3385\"}],\"center\":[{\"id\":\"3387\"},{\"id\":\"3391\"}],\"left\":[{\"id\":\"3388\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"3411\"}],\"title\":{\"id\":\"3376\"},\"toolbar\":{\"id\":\"3400\"},\"x_range\":{\"id\":\"3374\"},\"x_scale\":{\"id\":\"3381\"},\"y_range\":{\"id\":\"3379\"},\"y_scale\":{\"id\":\"3383\"}},\"id\":\"3375\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{},\"id\":\"3383\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"2291\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"3395\",\"type\":\"SaveTool\"},{\"attributes\":{\"source\":{\"id\":\"2171\"}},\"id\":\"3412\",\"type\":\"CDSView\"},{\"attributes\":{\"factors\":[[\"matplotlib\",\"Star\"],[\"matplotlib\",\"Commits\"],[\"matplotlib\",\"Contributors\"],[\"bokeh\",\"Star\"],[\"bokeh\",\"Commits\"],[\"bokeh\",\"Contributors\"],[\"pyecharts\",\"Star\"],[\"pyecharts\",\"Commits\"],[\"pyecharts\",\"Contributors\"],[\"seaborn\",\"Star\"],[\"seaborn\",\"Commits\"],[\"seaborn\",\"Contributors\"],[\"plotly\",\"Star\"],[\"plotly\",\"Commits\"],[\"plotly\",\"Contributors\"],[\"ggplot2\",\"Star\"],[\"ggplot2\",\"Commits\"],[\"ggplot2\",\"Contributors\"]],\"range_padding\":0.1},\"id\":\"3374\",\"type\":\"FactorRange\"},{\"attributes\":{\"formatter\":{\"id\":\"3529\"},\"major_label_orientation\":1,\"ticker\":{\"id\":\"3386\"}},\"id\":\"3385\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"data_source\":{\"id\":\"2171\"},\"glyph\":{\"id\":\"3409\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"3410\"},\"selection_glyph\":null,\"view\":{\"id\":\"3412\"}},\"id\":\"3411\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"3531\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"3529\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{},\"id\":\"3393\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"3398\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"overlay\":{\"id\":\"3398\"}},\"id\":\"3394\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"3392\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"3397\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"3396\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"3389\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"3381\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"3409\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"3386\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"3410\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2290\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"axis\":{\"id\":\"3388\"},\"dimension\":1,\"ticker\":null},\"id\":\"3391\",\"type\":\"Grid\"},{\"attributes\":{\"start\":0},\"id\":\"3379\",\"type\":\"DataRange1d\"},{\"attributes\":{\"formatter\":{\"id\":\"3531\"},\"ticker\":{\"id\":\"3389\"}},\"id\":\"3388\",\"type\":\"LinearAxis\"},{\"attributes\":{\"text\":\"Fruit Counts by Year\"},\"id\":\"3376\",\"type\":\"Title\"},{\"attributes\":{\"data\":{\"counts\":[9678,29503,808,11034,17673,357,5387,1321,18,6038,2316,98,4928,3370,76,3783,4286,184],\"x\":[[\"matplotlib\",\"Star\"],[\"matplotlib\",\"Commits\"],[\"matplotlib\",\"Contributors\"],[\"bokeh\",\"Star\"],[\"bokeh\",\"Commits\"],[\"bokeh\",\"Contributors\"],[\"pyecharts\",\"Star\"],[\"pyecharts\",\"Commits\"],[\"pyecharts\",\"Contributors\"],[\"seaborn\",\"Star\"],[\"seaborn\",\"Commits\"],[\"seaborn\",\"Contributors\"],[\"plotly\",\"Star\"],[\"plotly\",\"Commits\"],[\"plotly\",\"Contributors\"],[\"ggplot2\",\"Star\"],[\"ggplot2\",\"Commits\"],[\"ggplot2\",\"Contributors\"]]},\"selected\":{\"id\":\"2291\"},\"selection_policy\":{\"id\":\"2290\"}},\"id\":\"2171\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"3392\"},{\"id\":\"3393\"},{\"id\":\"3394\"},{\"id\":\"3395\"},{\"id\":\"3396\"},{\"id\":\"3397\"},{\"id\":\"3399\"}]},\"id\":\"3400\",\"type\":\"Toolbar\"},{\"attributes\":{\"callback\":null,\"tooltips\":[[\"star\",\"@star_count\"]]},\"id\":\"3399\",\"type\":\"HoverTool\"},{\"attributes\":{\"axis\":{\"id\":\"3385\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"3387\",\"type\":\"Grid\"}],\"root_ids\":[\"3375\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"e9e56532-60d9-4b78-a25e-51ad22290e27\",\"root_ids\":[\"3375\"],\"roots\":{\"3375\":\"5b5e0a96-f3a0-4efe-89d8-a0723ea08163\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "3375"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# 画布\n",
    "p = figure(x_range=FactorRange(*x), plot_height=350, title=\"Fruit Counts by Year\",\n",
    "           tooltips=TOOLTIPS\n",
    "#            toolbar_location=None, tools=\"\"\n",
    "          )\n",
    "# 柱状图\n",
    "p.vbar(x='x', top='counts', width=0.9, source=source)\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xaxis.major_label_orientation = 1\n",
    "p.xgrid.grid_line_color = None\n",
    "\n",
    "TOOLTIPS = [\n",
    "    (\"star\",\"@star_count\"),\n",
    "    (\"commit\",\"@commit_count\"),\n",
    "    (\"star\",\"@star_count\"),\n",
    "]\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"250aa93f-4a30-4030-8bec-7d38abd43bd7\" data-root-id=\"2173\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"0ecb2f48-4d13-475e-85ac-0b642bd49a3a\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"2183\"}],\"center\":[{\"id\":\"2185\"},{\"id\":\"2189\"}],\"left\":[{\"id\":\"2186\"}],\"plot_height\":350,\"renderers\":[{\"id\":\"2207\"},{\"id\":\"2344\"},{\"id\":\"2481\"}],\"title\":{\"id\":\"2174\"},\"toolbar\":{\"id\":\"2197\"},\"x_range\":{\"id\":\"2172\"},\"x_scale\":{\"id\":\"2179\"},\"y_range\":{\"id\":\"2177\"},\"y_scale\":{\"id\":\"2181\"}},\"id\":\"2173\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"data_source\":{\"id\":\"2171\"},\"glyph\":{\"id\":\"2342\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"2343\"},\"selection_glyph\":null,\"view\":{\"id\":\"2345\"}},\"id\":\"2344\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"axis\":{\"id\":\"2183\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"2185\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"2191\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"fill_color\":{\"field\":\"x\",\"transform\":{\"id\":\"2477\"}},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"2479\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2291\",\"type\":\"Selection\"},{\"attributes\":{\"end\":2,\"factors\":[\"Star\",\"Commits\",\"Contributors\"],\"palette\":[\"#c9d9d3\",\"#718dbf\",\"#e84d60\"],\"start\":1},\"id\":\"2340\",\"type\":\"CategoricalColorMapper\"},{\"attributes\":{\"formatter\":{\"id\":\"2285\"},\"major_label_orientation\":1,\"ticker\":{\"id\":\"2184\"}},\"id\":\"2183\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"end\":2,\"factors\":[\"Star\",\"Commits\",\"Contributors\"],\"palette\":[\"#c9d9d3\",\"#718dbf\",\"#e84d60\"],\"start\":1},\"id\":\"2477\",\"type\":\"CategoricalColorMapper\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"x\",\"transform\":{\"id\":\"2477\"}},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"2480\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2190\",\"type\":\"PanTool\"},{\"attributes\":{\"axis\":{\"id\":\"2186\"},\"dimension\":1,\"ticker\":null},\"id\":\"2189\",\"type\":\"Grid\"},{\"attributes\":{\"data_source\":{\"id\":\"2171\"},\"glyph\":{\"id\":\"2479\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"2480\"},\"selection_glyph\":null,\"view\":{\"id\":\"2482\"}},\"id\":\"2481\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"2193\",\"type\":\"SaveTool\"},{\"attributes\":{},\"id\":\"2285\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"source\":{\"id\":\"2171\"}},\"id\":\"2482\",\"type\":\"CDSView\"},{\"attributes\":{\"formatter\":{\"id\":\"2287\"},\"ticker\":{\"id\":\"2187\"}},\"id\":\"2186\",\"type\":\"LinearAxis\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"field\":\"x\",\"transform\":{\"id\":\"2340\"}},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"2343\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2194\",\"type\":\"ResetTool\"},{\"attributes\":{\"data_source\":{\"id\":\"2171\"},\"glyph\":{\"id\":\"2205\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"2206\"},\"selection_glyph\":null,\"view\":{\"id\":\"2208\"}},\"id\":\"2207\",\"type\":\"GlyphRenderer\"},{\"attributes\":{},\"id\":\"2187\",\"type\":\"BasicTicker\"},{\"attributes\":{},\"id\":\"2287\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{},\"id\":\"2195\",\"type\":\"HelpTool\"},{\"attributes\":{\"source\":{\"id\":\"2171\"}},\"id\":\"2345\",\"type\":\"CDSView\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"2205\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2184\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"text\":\"Fruit Counts by Year\"},\"id\":\"2174\",\"type\":\"Title\"},{\"attributes\":{\"overlay\":{\"id\":\"2196\"}},\"id\":\"2192\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"2179\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"2206\",\"type\":\"VBar\"},{\"attributes\":{\"factors\":[[\"matplotlib\",\"Star\"],[\"matplotlib\",\"Commits\"],[\"matplotlib\",\"Contributors\"],[\"bokeh\",\"Star\"],[\"bokeh\",\"Commits\"],[\"bokeh\",\"Contributors\"],[\"pyecharts\",\"Star\"],[\"pyecharts\",\"Commits\"],[\"pyecharts\",\"Contributors\"],[\"seaborn\",\"Star\"],[\"seaborn\",\"Commits\"],[\"seaborn\",\"Contributors\"],[\"plotly\",\"Star\"],[\"plotly\",\"Commits\"],[\"plotly\",\"Contributors\"],[\"ggplot2\",\"Star\"],[\"ggplot2\",\"Commits\"],[\"ggplot2\",\"Contributors\"]],\"range_padding\":0.1},\"id\":\"2172\",\"type\":\"FactorRange\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"2190\"},{\"id\":\"2191\"},{\"id\":\"2192\"},{\"id\":\"2193\"},{\"id\":\"2194\"},{\"id\":\"2195\"}]},\"id\":\"2197\",\"type\":\"Toolbar\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"2196\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"2290\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"fill_color\":{\"field\":\"x\",\"transform\":{\"id\":\"2340\"}},\"line_color\":{\"value\":\"white\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"2342\",\"type\":\"VBar\"},{\"attributes\":{\"source\":{\"id\":\"2171\"}},\"id\":\"2208\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"2181\",\"type\":\"LinearScale\"},{\"attributes\":{\"data\":{\"counts\":[9678,29503,808,11034,17673,357,5387,1321,18,6038,2316,98,4928,3370,76,3783,4286,184],\"x\":[[\"matplotlib\",\"Star\"],[\"matplotlib\",\"Commits\"],[\"matplotlib\",\"Contributors\"],[\"bokeh\",\"Star\"],[\"bokeh\",\"Commits\"],[\"bokeh\",\"Contributors\"],[\"pyecharts\",\"Star\"],[\"pyecharts\",\"Commits\"],[\"pyecharts\",\"Contributors\"],[\"seaborn\",\"Star\"],[\"seaborn\",\"Commits\"],[\"seaborn\",\"Contributors\"],[\"plotly\",\"Star\"],[\"plotly\",\"Commits\"],[\"plotly\",\"Contributors\"],[\"ggplot2\",\"Star\"],[\"ggplot2\",\"Commits\"],[\"ggplot2\",\"Contributors\"]]},\"selected\":{\"id\":\"2291\"},\"selection_policy\":{\"id\":\"2290\"}},\"id\":\"2171\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"start\":0},\"id\":\"2177\",\"type\":\"DataRange1d\"}],\"root_ids\":[\"2173\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"0ecb2f48-4d13-475e-85ac-0b642bd49a3a\",\"root_ids\":[\"2173\"],\"roots\":{\"2173\":\"250aa93f-4a30-4030-8bec-7d38abd43bd7\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "2173"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "## 增加分组柱状图颜色\n",
    "from bokeh.transform import factor_cmap\n",
    "\n",
    "palette = [\"#c9d9d3\", \"#718dbf\", \"#e84d60\"]\n",
    "\n",
    "# 绘图\n",
    "p.vbar(x='x', top='counts', width=0.9, source=source, line_color=\"white\",\n",
    "       fill_color=factor_cmap('x', palette=palette, factors=group, start=1, end=2))\n",
    "\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xaxis.major_label_orientation = 1\n",
    "p.xgrid.grid_line_color = None\n",
    "\n",
    "\n",
    "\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"e24e2cfe-3755-4834-a782-3a34b0f6f5eb\" data-root-id=\"1852\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"6a386544-b37f-4268-9fd6-41b5bbce0710\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"1860\"}],\"center\":[{\"id\":\"1862\"},{\"id\":\"1866\"}],\"left\":[{\"id\":\"1863\"}],\"plot_height\":400,\"renderers\":[{\"id\":\"1884\"}],\"title\":{\"id\":\"1943\"},\"toolbar\":{\"id\":\"1874\"},\"x_range\":{\"id\":\"1851\"},\"x_scale\":{\"id\":\"1856\"},\"y_range\":{\"id\":\"1854\"},\"y_scale\":{\"id\":\"1858\"}},\"id\":\"1852\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"text\":\"\"},\"id\":\"1943\",\"type\":\"Title\"},{\"attributes\":{\"formatter\":{\"id\":\"1947\"},\"ticker\":{\"id\":\"1864\"}},\"id\":\"1863\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"1872\",\"type\":\"HelpTool\"},{\"attributes\":{},\"id\":\"1861\",\"type\":\"CategoricalTicker\"},{\"attributes\":{\"source\":{\"id\":\"1850\"}},\"id\":\"1885\",\"type\":\"CDSView\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"1867\"},{\"id\":\"1868\"},{\"id\":\"1869\"},{\"id\":\"1870\"},{\"id\":\"1871\"},{\"id\":\"1872\"}]},\"id\":\"1874\",\"type\":\"Toolbar\"},{\"attributes\":{\"axis\":{\"id\":\"1863\"},\"dimension\":1,\"ticker\":null},\"id\":\"1866\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1856\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"1873\",\"type\":\"BoxAnnotation\"},{\"attributes\":{},\"id\":\"1864\",\"type\":\"BasicTicker\"},{\"attributes\":{\"formatter\":{\"id\":\"1945\"},\"major_label_orientation\":1,\"ticker\":{\"id\":\"1861\"}},\"id\":\"1860\",\"type\":\"CategoricalAxis\"},{\"attributes\":{},\"id\":\"1951\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"1871\",\"type\":\"ResetTool\"},{\"attributes\":{\"data\":{\"counts\":[9678,29503,808,11034,17673,357,5387,1321,18,6038,2316,98,4928,3370,76,3783,4286,184],\"x\":[[\"matplotlib\",\"star\"],[\"matplotlib\",\"commits\"],[\"matplotlib\",\"contributes\"],[\"bokeh\",\"star\"],[\"bokeh\",\"commits\"],[\"bokeh\",\"contributes\"],[\"pyecharts\",\"star\"],[\"pyecharts\",\"commits\"],[\"pyecharts\",\"contributes\"],[\"seaborn\",\"star\"],[\"seaborn\",\"commits\"],[\"seaborn\",\"contributes\"],[\"plotly\",\"star\"],[\"plotly\",\"commits\"],[\"plotly\",\"contributes\"],[\"ggplot2\",\"star\"],[\"ggplot2\",\"commits\"],[\"ggplot2\",\"contributes\"]]},\"selected\":{\"id\":\"1951\"},\"selection_policy\":{\"id\":\"1950\"}},\"id\":\"1850\",\"type\":\"ColumnDataSource\"},{\"attributes\":{\"fill_color\":{\"value\":\"pink\"},\"line_color\":{\"value\":\"pink\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1882\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1945\",\"type\":\"CategoricalTickFormatter\"},{\"attributes\":{\"factors\":[[\"matplotlib\",\"star\"],[\"matplotlib\",\"commits\"],[\"matplotlib\",\"contributes\"],[\"bokeh\",\"star\"],[\"bokeh\",\"commits\"],[\"bokeh\",\"contributes\"],[\"pyecharts\",\"star\"],[\"pyecharts\",\"commits\"],[\"pyecharts\",\"contributes\"],[\"seaborn\",\"star\"],[\"seaborn\",\"commits\"],[\"seaborn\",\"contributes\"],[\"plotly\",\"star\"],[\"plotly\",\"commits\"],[\"plotly\",\"contributes\"],[\"ggplot2\",\"star\"],[\"ggplot2\",\"commits\"],[\"ggplot2\",\"contributes\"]],\"range_padding\":0.1},\"id\":\"1851\",\"type\":\"FactorRange\"},{\"attributes\":{\"start\":0},\"id\":\"1854\",\"type\":\"DataRange1d\"},{\"attributes\":{},\"id\":\"1870\",\"type\":\"SaveTool\"},{\"attributes\":{\"axis\":{\"id\":\"1860\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"1862\",\"type\":\"Grid\"},{\"attributes\":{},\"id\":\"1947\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"pink\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"pink\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"1883\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"1867\",\"type\":\"PanTool\"},{\"attributes\":{},\"id\":\"1868\",\"type\":\"WheelZoomTool\"},{\"attributes\":{},\"id\":\"1858\",\"type\":\"LinearScale\"},{\"attributes\":{\"overlay\":{\"id\":\"1873\"}},\"id\":\"1869\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"1950\",\"type\":\"UnionRenderers\"},{\"attributes\":{\"data_source\":{\"id\":\"1850\"},\"glyph\":{\"id\":\"1882\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"1883\"},\"selection_glyph\":null,\"view\":{\"id\":\"1885\"}},\"id\":\"1884\",\"type\":\"GlyphRenderer\"}],\"root_ids\":[\"1852\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"6a386544-b37f-4268-9fd6-41b5bbce0710\",\"root_ids\":[\"1852\"],\"roots\":{\"1852\":\"e24e2cfe-3755-4834-a782-3a34b0f6f5eb\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "1852"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.io import show, output_file\n",
    "from bokeh.models import ColumnDataSource\n",
    "from bokeh.palettes import Spectral6\n",
    "from bokeh.plotting import figure\n",
    "from bokeh.transform import factor_cmap\n",
    "from bokeh.models import ColumnDataSource, FactorRange\n",
    "\n",
    "visualization_tools = ['matplotlib', 'bokeh', 'pyecharts', 'seaborn', 'plotly', 'ggplot2']\n",
    "indicators = ['star', 'commits', 'contributes']\n",
    "data = {'visualization_tools' : visualization_tools,\n",
    "        'star'   : [9678,11034,5387,6038,4928,3783],\n",
    "        'commits'   : [29503,17673,1321,2316,3370,4286],\n",
    "        'contributes'   : [808,357,18,98,76,184]}\n",
    "\n",
    "\n",
    "# 创建复合列表 \n",
    "x = [ (visualization_tool, indicator) for visualization_tool in visualization_tools for indicator in indicators ]\n",
    "counts = sum(zip(data['star'], data['commits'], data['contributes']), ()) # 分组求和(堆叠总数)\n",
    "source = ColumnDataSource(data=dict(x=x, counts=counts))\n",
    "\n",
    "# 画布\n",
    "p = figure(x_range=FactorRange(*x), plot_height=400\n",
    "#            toolbar_location=None, tools=\"\"\n",
    "          )\n",
    "\n",
    "# 柱状图\n",
    "p.vbar(x='x', top='counts', width=0.9, source=source,color='pink')\n",
    "\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xaxis.major_label_orientation = 1\n",
    "p.xgrid.grid_line_color = None\n",
    "\n",
    "# 显示\n",
    "show(p)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "\n",
       "  <div class=\"bk-root\" id=\"0cbf7ec2-d03e-4f22-ba22-e66f70580a0d\" data-root-id=\"2008\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "(function(root) {\n",
       "  function embed_document(root) {\n",
       "    \n",
       "  var docs_json = {\"6cd71b9d-2462-48bb-8b8e-7ac5d6018668\":{\"roots\":{\"references\":[{\"attributes\":{\"below\":[{\"id\":\"2016\"}],\"center\":[{\"id\":\"2018\"},{\"id\":\"2022\"}],\"left\":[{\"id\":\"2019\"}],\"plot_height\":400,\"renderers\":[{\"id\":\"2040\"}],\"title\":{\"id\":\"2108\"},\"toolbar\":{\"id\":\"2030\"},\"x_range\":{\"id\":\"2007\"},\"x_scale\":{\"id\":\"2012\"},\"y_range\":{\"id\":\"2010\"},\"y_scale\":{\"id\":\"2014\"}},\"id\":\"2008\",\"subtype\":\"Figure\",\"type\":\"Plot\"},{\"attributes\":{\"fill_alpha\":{\"value\":0.1},\"fill_color\":{\"value\":\"#1f77b4\"},\"line_alpha\":{\"value\":0.1},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"2039\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2017\",\"type\":\"CategoricalTicker\"},{\"attributes\":{},\"id\":\"2012\",\"type\":\"CategoricalScale\"},{\"attributes\":{\"formatter\":{\"id\":\"2112\"},\"ticker\":{\"id\":\"2020\"}},\"id\":\"2019\",\"type\":\"LinearAxis\"},{\"attributes\":{},\"id\":\"2014\",\"type\":\"LinearScale\"},{\"attributes\":{},\"id\":\"2020\",\"type\":\"BasicTicker\"},{\"attributes\":{\"axis\":{\"id\":\"2016\"},\"grid_line_color\":null,\"ticker\":null},\"id\":\"2018\",\"type\":\"Grid\"},{\"attributes\":{\"formatter\":{\"id\":\"2110\"},\"major_label_orientation\":1,\"ticker\":{\"id\":\"2017\"}},\"id\":\"2016\",\"type\":\"CategoricalAxis\"},{\"attributes\":{\"fill_color\":{\"value\":\"#1f77b4\"},\"line_color\":{\"value\":\"#1f77b4\"},\"top\":{\"field\":\"counts\"},\"width\":{\"value\":0.9},\"x\":{\"field\":\"x\"}},\"id\":\"2038\",\"type\":\"VBar\"},{\"attributes\":{},\"id\":\"2112\",\"type\":\"BasicTickFormatter\"},{\"attributes\":{\"factors\":[[\"star\",\"matplotlib\"],[\"star\",\"bokeh\"],[\"star\",\"pyecharts\"],[\"star\",\"seaborn\"],[\"star\",\"plotly\"],[\"star\",\"ggplot2\"],[\"commits\",\"matplotlib\"],[\"commits\",\"bokeh\"],[\"commits\",\"pyecharts\"],[\"commits\",\"seaborn\"],[\"commits\",\"plotly\"],[\"commits\",\"ggplot2\"],[\"contributes\",\"matplotlib\"],[\"contributes\",\"bokeh\"],[\"contributes\",\"pyecharts\"],[\"contributes\",\"seaborn\"],[\"contributes\",\"plotly\"],[\"contributes\",\"ggplot2\"]],\"range_padding\":0.1},\"id\":\"2007\",\"type\":\"FactorRange\"},{\"attributes\":{\"start\":0},\"id\":\"2010\",\"type\":\"DataRange1d\"},{\"attributes\":{\"active_drag\":\"auto\",\"active_inspect\":\"auto\",\"active_multi\":null,\"active_scroll\":\"auto\",\"active_tap\":\"auto\",\"tools\":[{\"id\":\"2023\"},{\"id\":\"2024\"},{\"id\":\"2025\"},{\"id\":\"2026\"},{\"id\":\"2027\"},{\"id\":\"2028\"}]},\"id\":\"2030\",\"type\":\"Toolbar\"},{\"attributes\":{},\"id\":\"2116\",\"type\":\"Selection\"},{\"attributes\":{},\"id\":\"2026\",\"type\":\"SaveTool\"},{\"attributes\":{\"source\":{\"id\":\"2006\"}},\"id\":\"2041\",\"type\":\"CDSView\"},{\"attributes\":{},\"id\":\"2115\",\"type\":\"UnionRenderers\"},{\"attributes\":{},\"id\":\"2024\",\"type\":\"WheelZoomTool\"},{\"attributes\":{\"axis\":{\"id\":\"2019\"},\"dimension\":1,\"ticker\":null},\"id\":\"2022\",\"type\":\"Grid\"},{\"attributes\":{\"bottom_units\":\"screen\",\"fill_alpha\":0.5,\"fill_color\":\"lightgrey\",\"left_units\":\"screen\",\"level\":\"overlay\",\"line_alpha\":1.0,\"line_color\":\"black\",\"line_dash\":[4,4],\"line_width\":2,\"right_units\":\"screen\",\"top_units\":\"screen\"},\"id\":\"2029\",\"type\":\"BoxAnnotation\"},{\"attributes\":{\"overlay\":{\"id\":\"2029\"}},\"id\":\"2025\",\"type\":\"BoxZoomTool\"},{\"attributes\":{},\"id\":\"2028\",\"type\":\"HelpTool\"},{\"attributes\":{\"data\":{\"counts\":[9678,11034,5387,6038,4928,3783,29503,17673,1321,2316,3370,4286,808,357,18,98,76,184],\"x\":[[\"star\",\"matplotlib\"],[\"star\",\"bokeh\"],[\"star\",\"pyecharts\"],[\"star\",\"seaborn\"],[\"star\",\"plotly\"],[\"star\",\"ggplot2\"],[\"commits\",\"matplotlib\"],[\"commits\",\"bokeh\"],[\"commits\",\"pyecharts\"],[\"commits\",\"seaborn\"],[\"commits\",\"plotly\"],[\"commits\",\"ggplot2\"],[\"contributes\",\"matplotlib\"],[\"contributes\",\"bokeh\"],[\"contributes\",\"pyecharts\"],[\"contributes\",\"seaborn\"],[\"contributes\",\"plotly\"],[\"contributes\",\"ggplot2\"]]},\"selected\":{\"id\":\"2116\"},\"selection_policy\":{\"id\":\"2115\"}},\"id\":\"2006\",\"type\":\"ColumnDataSource\"},{\"attributes\":{},\"id\":\"2027\",\"type\":\"ResetTool\"},{\"attributes\":{},\"id\":\"2023\",\"type\":\"PanTool\"},{\"attributes\":{\"data_source\":{\"id\":\"2006\"},\"glyph\":{\"id\":\"2038\"},\"hover_glyph\":null,\"muted_glyph\":null,\"nonselection_glyph\":{\"id\":\"2039\"},\"selection_glyph\":null,\"view\":{\"id\":\"2041\"}},\"id\":\"2040\",\"type\":\"GlyphRenderer\"},{\"attributes\":{\"text\":\"\"},\"id\":\"2108\",\"type\":\"Title\"},{\"attributes\":{},\"id\":\"2110\",\"type\":\"CategoricalTickFormatter\"}],\"root_ids\":[\"2008\"]},\"title\":\"Bokeh Application\",\"version\":\"2.1.1\"}};\n",
       "  var render_items = [{\"docid\":\"6cd71b9d-2462-48bb-8b8e-7ac5d6018668\",\"root_ids\":[\"2008\"],\"roots\":{\"2008\":\"0cbf7ec2-d03e-4f22-ba22-e66f70580a0d\"}}];\n",
       "  root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n",
       "\n",
       "  }\n",
       "  if (root.Bokeh !== undefined) {\n",
       "    embed_document(root);\n",
       "  } else {\n",
       "    var attempts = 0;\n",
       "    var timer = setInterval(function(root) {\n",
       "      if (root.Bokeh !== undefined) {\n",
       "        clearInterval(timer);\n",
       "        embed_document(root);\n",
       "      } else {\n",
       "        attempts++;\n",
       "        if (attempts > 100) {\n",
       "          clearInterval(timer);\n",
       "          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n",
       "        }\n",
       "      }\n",
       "    }, 10, root)\n",
       "  }\n",
       "})(window);"
      ],
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "2008"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from bokeh.models import ColumnDataSource, FactorRange\n",
    "information1 = ['star', 'commits', 'contributes']\n",
    "visualization_tools = ['matplotlib', 'bokeh', 'pyecharts', 'seaborn', 'plotly', 'ggplot2']\n",
    "data = {'information1' : information1,\n",
    "        'matplotlib'   : [9678,29503,808],\n",
    "        'bokeh'   : [11034,17673,357],\n",
    "        'pyecharts'   : [5387,1321,18],\n",
    "       'seaborn' :[6038,2316,98],\n",
    "       'plotly' :[4928,3370,76],\n",
    "        'ggplot2':[3783,4286,184]}\n",
    "\n",
    "\n",
    "# 创建复合列表 \n",
    "x = [ (information, visualization_tool) for information in information1 for visualization_tool in visualization_tools ]\n",
    "counts = sum(zip(data['matplotlib'], data['bokeh'], data['pyecharts'],data['seaborn'],data['plotly'],data['ggplot2']), ()) # 分组求和(堆叠总数)\n",
    "source = ColumnDataSource(data=dict(x=x, counts=counts))\n",
    "\n",
    "\n",
    "# 画布\n",
    "p = figure(x_range=FactorRange(*x), plot_height=400\n",
    "#            toolbar_location=None, tools=\"\"\n",
    "          )\n",
    "\n",
    "# 柱状图\n",
    "p.vbar(x='x', top='counts', width=0.9, source=source)\n",
    "\n",
    "# 其他\n",
    "p.y_range.start = 0\n",
    "p.x_range.range_padding = 0.1\n",
    "p.xaxis.major_label_orientation = 1\n",
    "p.xgrid.grid_line_color = None\n",
    "\n",
    "# 显示\n",
    "show(p)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "383.188px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
